分析:就是找到以每个节点为根节点的树的重心 树的重心可以看这三篇文章: 1:http://wenku.baidu.com/link?url=yc-3QD55hbCaRYEGsF2fPpXYg-iO63WtCFbg4RXHjERwk8piK3dgeKKvUBprOW8hJ7aN7h4ZC09QE9x6hYV3lD7bEvyOv_l1E-ucxjHJzqi 2:http://fanhq666.blog.163.com/blog/static/81943426201172472943638/ 3:ht…
题目链接: 题目 D. Kay and Snowflake time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output 问题描述 After the piece of a devilish mirror hit the Kay's eye, he is no longer interested in the beauty of the r…
http://codeforces.com/contest/686/problem/D 给出q个询问,每次要求询问以x为根的子树中,哪一个点是重心. 树的重心:求以cur为根的子树的重心,就是要找一个点,使得删除这个点后,分开来的零散的子树中,节点数的最大值最小.并且最大值最多也只是son[cur] / 2,因为最坏情况(最难分)也就是一条直线,选中间点就可以了. 例如 询问1的时候,就应该删除3,然后得到4个零散分支,2个大小是1,2个是2. 算法思路: 直观来说,应该是删除那个儿子数最多的那…
树的重心,树形$dp$. 记录以$x$为$root$的子树的节点个数为$sz[x]$,重儿子为$son[x]$,重心为$ans[x]$. 首先要知道一个结论:以$x$为$root$的子树的重心$ans[x]$,一定在$ans[son[x]]$到$x$的路径上,即以$x$的重儿子为根的子树的重心到$x$的路径上. 因此,只要从节点$ans[son[x]]$依次往$father$枚举就可以了. 如果枚举到节点$g$,发现$g$节点满足$sz\left[ {son\left[ g \right]} \…
D. Kay and Snowflake     After the piece of a devilish mirror hit the Kay's eye, he is no longer interested in the beauty of the roses. Now he likes to watch snowflakes. Once upon a time, he found a huge snowflake that has a form of the tree (connect…
[题目]C. Centroids [题意]给定一棵树,求每个点能否通过 [ 移动一条边使之仍为树 ] 这一操作成为树的重心.n<=4*10^5. [算法]树的重心 [题解]若树存在双重心,则对于任何一个点将另一边的n/2个点取下来接上去即可,均成立. 若树为单重心,假设w为树的重心及根,x为当前考虑节点. 由于w是重心,x的父亲这棵子树必定超过n/2,此时最优策略只能在(w,son[w])中砍下最大的一棵子树接到x下面(除了x所在子树). 复杂度O(n). #include<cstdio>…
题目链接: E. Connecting Universities time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output Treeland is a country in which there are n towns connected by n - 1 two-way road such that it's possible to…
After the piece of a devilish mirror hit the Kay's eye, he is no longer interested in the beauty of the roses. Now he likes to watch snowflakes. Once upon a time, he found a huge snowflake that has a form of the tree (connected acyclic graph) consist…
B. Kay and Snowflake 题目连接: http://www.codeforces.com/contest/685/problem/B Description After the piece of a devilish mirror hit the Kay's eye, he is no longer interested in the beauty of the roses. Now he likes to watch snowflakes. Once upon a time,…
Kay and Snowflake CodeForces - 686D 题意:给一棵有根树,有很多查询(100000级别的),查询是求以任意一点为根的子树的任意重心. 方法很多,但是我一个都不会 重心几个定义/性质: 1.从树中去掉某点以及和该点相连的所有边后,整棵树变为许多"块".去掉任意一个重心(相比于去掉其他点)可以使得生成的各个"块"的节点数的最大值最少. 类似的一个:对于一棵树n个节点的无根树,找到一个点,使得把树变成以该点为根的有根树时,最大子树的结点数…