B Gift Node
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 524288/524288K (Java/Other)
Problem Description
You are given a tree with n nodes (numbered from 1 to n). The root is node 1. Each edge in this tree has a particular color which is specified by an integer from 1 to 10^8. We define a path on the tree as a gift path if and only if adjacent edges on the path have different colors. In addition, we define a node as a gift node, if all the paths starting at this node are gift paths.
We have Q questions for you. For each question, you are given a node R, and you need to find out the number of gift nodes in the subtree of node R. Note that when we say a node in some subtree is a gift node, only paths in that subtree will be considered.Input
First line contains an integer n(1≤n≤200000).
Each of the next n-1 lines contains three integers 1≤Ai,Bi,Ci(Ai,Bi,Ci≤n,Ai≠Bi) , represents an edge of col
2019ACM/CCPC吉林省赛——B.Gift Node【DFS+差分约束】
最新推荐文章于 2023-04-05 19:02:19 发布