cf 701 E - Connecting Universities
Descrition
给你一颗\(n\le 2*10^5\)个点的树, 有\(2*k(2k\le n)\)座大学座落在点上
(任二大学不在同一个点)
求一种两两匹配的方案, 使得距离和最大
即\[maximize~\{~\sum_{each~pair~(x,y)} dis(x,y)~\}~\]
Solution 1
(1) 化简一下我们相当于要最小化 两两lca的深度和
我们先把这2k所大学按dfn序从小到大排好, 把前k个称为A部分, 后k个称为B部分
(2) 所有匹配均为\(A-B\)匹配
如果存在一个\(A-A'\)匹配, 那么一定也会存在一个$B-B' $匹配
此时通过交换匹配, 显然一定可以变优
(3) 引理: dfn区间[\(x,y\)]的公共lca 为 \(lca(x,r)\) 或 \(lca(l,r)\), 其中\(x\le l \le r\le y\)
首先[x,y]的公共lca为点x,点y的lca是显然的
\(x\to r\)相当于走到子树或者向上回溯然后往下走
如果\(x-r\)路径没有跨过lca, 如图1, 那么r-y就必定会跨过lca
如果\(x-r\)路径跨国了lca, 如图2, 那么引理成立

(4) 若\(x<y\in A\), 那么\(x' < y'\)
如果存在\(x<y<y'<x'\) , 我们可以交换匹配变成\(x-y', y-x'\), 解不会变差
\(lca(x, x') < one~of~lca(x, y')~and~lca(y, x')\)
\(lca(y, y') < both~of~lca(x, y')~and~lca(y, x')\)
(5) 匹配为\(i\to i+k\)
根据(2) , \(1\)至少要匹配到\(1+k\)的位置
根据\((4)\), 必须要\(i\to i+k\), 才能保证匹配位置足够选择
Solution 2
考虑每条边\(fa\to x\)
记\(x\)子树内有\(sub[x]\)所大学
那么\(x\)子树外有\(2k-sub[x]\)所大学
结论: 每条边被匹配恰 \(min(sub[x], 2k- sub[x])\)次
首先, 不可能超过这个次数
然后, 如果小于, 那么子树内部有一对匹配, 子树外部有一对匹配
通过交换匹配一定可以使得距离变长
知道每条边被匹配多少次后, 貌似可以用启发式合并vec的方式构造解
(行吧原题不要求构造解)
cf 701 E - Connecting Universities的更多相关文章
- codeforces 701 E. Connecting Universities(树+ 边的贡献)
题目链接:http://codeforces.com/contest/701/problem/E 题意:有n个城市构成一棵树,一个城市最多有一个学校,这n个城市一共2*k个学校,要对这2*k个学校进行 ...
- cf 700 B Connecting Universities
题意:现在给以一棵$n$个结点的树,并给你$2k$个结点,现在要求你把这些节点互相配对,使得互相配对的节点之间的距离(路径上经过边的数目)之和最大.数据范围$1 \leq n \leq 200000, ...
- Codeforces Round #364 (Div. 2) E. Connecting Universities
E. Connecting Universities time limit per test 3 seconds memory limit per test 256 megabytes input s ...
- Connecting Universities
Connecting Universities Treeland is a country in which there are n towns connected by n - 1 two-way ...
- Codeforces Round #364 (Div. 2) E. Connecting Universities (DFS)
E. Connecting Universities time limit per test 3 seconds memory limit per test 256 megabytes input s ...
- codeforces 701E E. Connecting Universities(树的重心)
题目链接: E. Connecting Universities time limit per test 3 seconds memory limit per test 256 megabytes i ...
- Codeforces 701E Connecting Universities 贪心
链接 Codeforces 701E Connecting Universities 题意 n个点的树,给你2*K个点,分成K对,使得两两之间的距离和最大 思路 贪心,思路挺巧妙的.首先dfs一遍记录 ...
- Codeforces 700B Connecting Universities - 贪心
Treeland is a country in which there are n towns connected by n - 1 two-way road such that it's poss ...
- cf701E Connecting Universities
Treeland is a country in which there are n towns connected by n - 1 two-way road such that it's poss ...
随机推荐
- RuPengGame游戏引擎 精灵 createSprite 创建 setSpritePosition 设置位置 playSpriteAnimate 播放动画 setSpriteFlipX设置翻转 精灵图片下载地址
package com.swift; import java.awt.Point; import com.rupeng.game.GameCore;//导入游戏引擎包 public class Gam ...
- java 程序设计第三次作业内容
第一题:输出结果是什么? System.out.println("5+5="+5+5); 第二题:输出结果是什么? int a=3,b; b=a++; sop("a=&q ...
- 谭浩强 c++程序设计第一章课后习题 第10题
#include <iostream> using namespace std; int main() { int a,b,c; cout<<"请输入三个整数类型的数 ...
- docker安装后无法启动问题
问题报错: Error starting daemon: Error initializing network controller: list bridge addresses failed: no ...
- 自动化运维工具——ansible命令使用(二)
一.Ansible系列命令使用 ansible命令执行过程 1 . 加载自己的配置文件 默认/etc/ansible/ansible.cfg 2 . 加载自己对应的模块文件,如command 3 . ...
- Nginx认证
Nginx 的 ngx_http_auth_basic_module模块允许通过使用“HTTP基本认证”协议验证用户名和密码来限制对资源的访问. 配置举例: location / { auth_bas ...
- SpringBoot-Security-用户权限分配-项目搭建
SpringBoot原则是约定优于配置,简化spring应用开发,去繁从简,产品级别的应用. SpringBoot有哪些优点1.快速创建独立运行的spring项目与主流框架集成 2.使用嵌入式的ser ...
- Debug调试文件
在debug.h中设置g_debug_switch即可控制调试级别. /* debug.c */ #include "debug.h" const char *get_log_le ...
- P3387 【模板】缩点
题目背景 缩点+DP 题目描述 给定一个n个点m条边有向图,每个点有一个权值,求一条路径,使路径经过的点权值之和最大.你只需要求出这个权值和. 允许多次经过一条边或者一个点,但是,重复经过的点,权值只 ...
- SJTU 1077 加分二叉树
http://acm.sjtu.edu.cn/OnlineJudge/problem/1077 题意: 设一个n个节点的二叉树tree的中序遍历为(l,2,3,…,n),其中数字1,2,3…,n为节点 ...