码迷,mamicode.com
首页 > 其他好文 > 详细

HDU 多校1.3

时间:2017-07-25 13:36:32      阅读:142      评论:0      收藏:0      [点我收藏+]

标签:nbsp   contain   contains   cep   min   ble   others   content   des   

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 c技术分享i技术分享技术分享 .

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 c技术分享i技术分享技术分享 , the color of node i技术分享 . (1c技术分享i技术分享n)技术分享

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

HDU 多校1.3

标签:nbsp   contain   contains   cep   min   ble   others   content   des   

原文地址:http://www.cnblogs.com/Roni-i/p/7233425.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!