Listing Tedious Paths

아직 제출이 없습니다시간 제한1초메모리 제한1024 MB

문제

A tree is a graph that is connected (there exists a path between any two of its vertices), undirected (the edges of the graph have no direction), and acyclic (there are no cycles).

A colorful tree is a tree in which each of its vertices has a specific color.

A tedious path is a path in the tree such that both the initial and final vertices have the same color, and there is no vertex or edge that appear more than once in the path. Note that the color of the intermediate vertices, if there are any, are irrelevant.

Given a colorful tree, with NN vertices, your task is calculate, for each of the edges, the number of tedious paths that go through that edge.

입력

The first line contains the number of vertices NN (1N1051 ≤ N ≤ 10^5). The second line contains NN integers C_1,,C_NC\_1, \dots , C\_N, where C_iC\_i (1C_iN1 ≤ C\_i ≤ N) represents the color of the vertex ii. The next N1N - 1 lines contains two integers each, uu and vv, representing an edge (1u,vN1 ≤ u, v ≤ N and uvu \ne v). It’s guaranteed that the given graph is a tree.

출력

Print N1N-1 integers, representing the number of tedious paths that go through each edge, following the same order of the edges as they are given in the input.