Description
Bobo has a tree with n vertices numbered by 1,2,…,n and (n-1) edges. The i-th vertex has color c
i, and the i-th edge connects vertices a
i and b
i.
Let C(x,y) denotes the set of colors in subtree rooted at vertex x deleting edge (x,y).
Bobo would like to know R_i which is the size of intersection of C(a
i,b
i) and C(b
i,a
i) for all 1≤i≤(n-1). (i.e. |C(a
i,b
i)∩C(b
i,a
i)|)
Input
The input contains at most 15 sets. For each set:
The first line contains an integer n (2≤n≤10
5).
The second line contains n integers c
1,c
2,…,c
n (1≤c_i≤n).
The i-th of the last (n-1) lines contains 2 integers a