Colorful Trees
시간 제한1초메모리 제한1024 MB
색이 칠해진 트리에서 각 간선마다 그 간선을 지나는 경로를 가진 같은 색 정점 쌍의 개수를 구한다.
문제
Given a tree with colored vertices, for each edge, how many pairs of vertices with the same color have that edge on the path between them? Note that since it’s a tree, each pair of nodes has exactly one path between them.
입력
The first line of input contains a single integer (), which is the number of nodes in the tree. The nodes are numbered from to .
Each of the next lines contains a single integer (). These are the colors of the nodes, in order.
Each of the next lines contains two integers and (), denoting an undirected edge from node to node .
출력
Output lines. On each line, output a single integer, which is the number of pairs of vertices with the same color that have that edge on the path between them. Output these answers for the edges in the order that they appear in the input.