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 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 (). The second line contains integers , where () represents the color of the vertex . The next lines contains two integers each, and , representing an edge ( and ). It’s guaranteed that the given graph is a tree.
출력
Print 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.