题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5423 Rikka with Tree Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 321 Accepted Submission(s): 162 Problem Description As we know, Rikka is p…
Problem Description As we know, Rikka is poor at math. Yuta is worrying about this situation, so he gives Rikka some math tasks to practice. There is one of them: For a tree T, let F(T,i) be the distance between vertice and vertice i.(The length of e…
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=5423 Problem Description As we know, Rikka is poor at math. Yuta is worrying about this situation, so he gives Rikka some math tasks to practice. There is one of them: For a tree T, let F(T,i) be t…
题目链接 Problem Description There is a tree with n nodes, each of which has a type of color represented by an integer, where the color of node i is ci. The path between each two different nodes is unique, of which we define the value as the number of di…
Problem Description As we know, Rikka is poor at math. Yuta is worrying about this situation, so he gives Rikka some math tasks to practice. There is one of them: For a tree T, let F(T,i) be the distance between vertice 1 and vertice i.(The length of…
Alyona and the Tree Descriptions 小灵决定节食,于是去森林里摘了些苹果.在那里,她意外地发现了一棵神奇的有根树,它的根在节点 1 上,每个节点和每条边上都有一个数字. 小灵注意到树上有一些节点不开心,所以她决定和它们一起玩. 如果节点 v 的子树中有一个节点 u 使得dist(v, u) > au ,那么节点 v 就会不开心.au 代表节点 u 上的数字,dist(v, u)代表连接节点 v 到节点 u 的所有边上的数字和,也就是两个节点的距离. 通过 1 条边连…
题目链接:http://codeforces.com/problemset/problem/682/C 题意:如果点v在点u的子树上且dist(u,v)>a[v]则u和其整个子树都将被删去,求被删去的点数. 思路:1为根节点,从1开始DFS遍历,记录距离dis为到祖宗节点的最大距离. #include<bits/stdc++.h> using namespace std; typedef long long ll; const int N=1e5+5; int a[N],num[N],a…