1691 - A Simple Tree Problem
Time Limit : 1 Second
Memory Limit : 512 MB
Submission: 7
Solved: 3
- Description
Given a colorful tree of n nodes and m queries, for each query, given a color c, tell the maximum distance for all nodes of color c.
- Input
There are several cases, first is the number of cases T. (T = 10).
For each case, the first line isan integer n(n <= 30000). In following there are n-1 lines. Each line has two integer u , v. indicate that there is an edge between node u and v.
The following line contains n integers, the i-th integer indicates the color if the i-th node.
The next line is an integer m(1<=m<=n). In following there are m lines. Each line has an integer c,
- Output
For each case, output the answer in a line.
- sample input
-
1 6 1 2 2 3 2 4 1 5 5 6 1 2 3 3 2 3 3 1 2 3
- sample output
-
0 2 4
- hint
Note that if less than two nodes of the given color appears, the answer is 0.
- source
- YY