HDU 多校1.3

Colorful Tree

Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 0    Accepted Submission(s): 0


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 different colors appearing in it.

Calculate the sum of values of all paths on the tree that has n(n1)2 paths in total.
 

 

Input
The input contains multiple test cases.

For each test case, the first line contains one positive integers n , indicating the number of node. (2n200000)

Next line contains n integers where the i -th integer represents ci , the color of node i . (1cin)

Each of the next n1 lines contains two positive integers x,y (1x,yn,xy) , meaning an edge between node x and node y .

It is guaranteed that these edges form a tree.
 

 

Output
For each test case, output " Case #x : y " in one line (without quotes), where x indicates the case number starting from 1 and y denotes the answer of corresponding case.
 

 

Sample Input
3 1 2 1 1 2 2 3 6 1 2 1 3 2 1 1 2 1 3 2 4 2 5 3 6
 

 

Sample Output
Case #1: 6 Case #2: 29
全部评论

相关推荐

投了十几个无人回应
花环鞣: 佬,我隔壁的
点赞 评论 收藏
分享
一拳打爆地球66:我TM没看错吧,50块一天还985、211研究生优先?那个**会去?
点赞 评论 收藏
分享
想踩缝纫机的小师弟练...:不理解你们这些人,要放记录就把对方公司名字放出来啊。不然怎么网暴他们
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务