2019ACM/CCPC吉林省赛——B.Gift Node【DFS+差分约束】

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值