Tree Intersection
题号: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 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 .
(i.e. )

输入描述:

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 a_i, b_i
().

输出描述:

For each set, (n - 1) integers .
示例1

输入

复制
4
1 2 2 1
1 2
2 3
3 4

输出

复制
1
2
1
示例2

输入

复制
5
1 1 2 1 2
1 3
2 3
3 5
4 5

输出

复制
1
1
2
1