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 nodes, each of which has a type of color represented by an integer, where the color of node is .

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 paths in total.
 

 

Input
The input contains multiple test cases.

For each test case, the first line contains one positive integers , indicating the number of node.

Next line contains integers where the -th integer represents , the color of node .

Each of the next lines contains two positive integers , meaning an edge between node and node .

It is guaranteed that these edges form a tree.
 

 

Output
For each test case, output "Case # : " in one line (without quotes), where indicates the case number starting from and 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

相关文章:

  • 2021-07-07
  • 2021-11-24
  • 2021-08-10
  • 2021-12-11
  • 2021-11-28
  • 2021-07-11
  • 2021-09-05
  • 2021-08-03
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-29
  • 2021-10-07
  • 2022-12-23
  • 2021-10-10
相关资源
相似解决方案