We are given a tree with N nodes. Each node has a color Ci. We are also given N−1 queries and in each query we are told to destroy a previously undestroyed edge. Every time we destroy an edge, we have to report the number of pairs of nodes that get disconnected. Here, two nodes i and j are said to be disconnected if before the destruction you could reach from i to j using edges not yet destroyed , and if Ci=Cj.
Constraint:
N≤300,000
C[i]≤100,000
Input:
The first line contains a single integer N. The next N−1 lines contain two space separated integers a and b which means that there is an edge between a and b in the tree. The next line contains N space separated integers where the i integer denotes the value of Ci. The last line contains N−1 space separated integers Di- the ith integer denotes that the Dthi edge (in the order in which edges are given in input) is deleted in the ith step.
Output:
For every deleted edge, output the number of disconnected values on a new line.
<insert later>