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…
Kay and Snowflake CodeForces - 686D 题意:给一棵有根树,有很多查询(100000级别的),查询是求以任意一点为根的子树的任意重心. 方法很多,但是我一个都不会 重心几个定义/性质: 1.从树中去掉某点以及和该点相连的所有边后,整棵树变为许多"块".去掉任意一个重心(相比于去掉其他点)可以使得生成的各个"块"的节点数的最大值最少. 类似的一个:对于一棵树n个节点的无根树,找到一个点,使得把树变成以该点为根的有根树时,最大子树的结点数…
大意:给定有根树, 求每个子树的重心 我太菜了啊, 只能想到暴力树剖, 然而这就是个B题, 感觉树剖+线段树二分还是挺难写的..... 看了题解发现重心一定在重儿子与根的树链上, 重心最多上跳n-1次, 直接暴力就行…
D - Kay and Snowflake 思路: 树的重心 利用重心的一个推论,树的重心必定在子树重心的连线上. 然后利用重心的性质,可知,如果有一颗子树的大小超过整棵树的大小的1/2,那么树的重心一定在这颗子树上. 利用以上两条,可知: 如果没有一颗子树的大小超过整棵树的大小的1/2,那么就可以以根节点为树的重心, 不然就从 超过1/2大小的子树 的重心 到 根节点 之间找整棵树的重心. 因为不会找重复的点,所以退化的复杂度为O(n) #include<bits/stdc++.h> usi…
http://poj.org/problem? id=1655 Balancing Act Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9072   Accepted: 3765 Description Consider a tree T with N (1 <= N <= 20,000) nodes numbered 1...N. Deleting any node from the tree yields a f…
Update:原来的洛谷U21715已成坑qwq 已经被某位管理员巨佬放进公共题库啦!又可以多一个AC记录啦! 洛谷题目传送门 其实也可以到这里交啦 思路分析 动态维护树的重心 题目中说到国家的首都会选在某个使得其他城市到它距离之和最小的城市,那不就是树的重心了嘛.树的重心性质真的很好,看看wuhulala巨佬的这篇博客. 网上大多数解法都是启发式合并.利用了以重心为根的子树大小不超过原树的一半,每次合并两颗树的时候,小的往大的上面合并,而且是一个点一个点地link上去,每次link完检查一下这…
题目链接: 题目 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…
分析:就是找到以每个节点为根节点的树的重心 树的重心可以看这三篇文章: 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 roses. No…
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…