给你一个树N个点,再给出Q个询问,问以x为根的子树中,重心是哪个?2≤n≤300000,1≤q≤30000 Sol:从下到上,根据性质做一下.1:如果某个点x,其子树y的大小超过总结点个数一半,则重心在y这个子树中.2:如果某个树的重心点,其上方点的个数多于其下方点的,则重心要上移 #include <bits/stdc++.h> using namespace std; const int N = 300000+10; int n,q; vector<int> G[N]; ///…
题目链接: 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…
CF685B Kay and Snowflake 链接 CF 题目大意 给你一颗树,询问子树的重心 思路 贪心? 重心肯定是向上走的,所以直接向上跳就好了. 不优秀的时候就不要跳了 ,因为以后也不能更新了. 复杂度O(n)(没大仔细想过) 代码 #include <bits/stdc++.h> using namespace std; const int N=3e5+7; int read() { int x=0,f=1;char s=getchar(); for(;s>'9'||s&l…
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…
题目链接: 题目 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…
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,…