题号:NC52808
时间限制:C/C++/Rust/Pascal 1秒,其他语言2秒
空间限制:C/C++/Rust/Pascal 32 M,其他语言64 M
Special Judge, 64bit IO Format: %lld
题目描述
Bobo has a tree with n vertices numbered by

and (n - 1) edges.
The i-th vertex has color

, and the i-th edge connects vertices

and

.
Let C(x, y) denotes the set of colors in subtree rooted at vertex x deleting edge (x, y).
Bobo would like to know

which is the size of intersection of
)
and
)
for all
)
.
(i.e.
%20%5Ccap%20C(b_i%2C%20a_i)%7C)
)
输入描述:
The input contains at most 15 sets. For each set:
The first line contains an integer n (
).
The second line contains n integers
(
).
The i-th of the last (n - 1) lines contains 2 integers 
(
).
输出描述:
For each set, (n - 1) integers
.
示例2
输入
复制
5
1 1 2 1 2
1 3
2 3
3 5
4 5