1641.
Colorful Tree
时间限制 3000 ms
内存限制 128 MB
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 $\frac{n(n-1)}{2}$ paths in total.
输入数据
输出数据
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.
样例输入
复制
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
\n
· · \n
· \n
· \n
\n
· · · · · \n
· \n
· \n
· \n
· \n
· \n
样例输出
复制
Case #1: 6
Case #2: 29
· · \n
· · \n