AT_abc482_e [ABC482E] Diameter Endpoint Colors
Description
You are given a tree $ T $ with $ N $ vertices numbered $ 1,2,\dots,N $ . For $ i=1,2,\dots,N-1 $ , the $ i $ -th edge connects vertices $ u_i $ and $ v_i $ .
Each vertex is painted in a color; vertex $ v $ is painted in color $ C_v $ .
Find the number of integer pairs $ (u,v) $ with $ 1 \leq u < v \leq N $ that satisfy all of the following conditions.
- Vertices $ u $ and $ v $ are painted in the same color.
- The length of the simple path connecting vertices $ u $ and $ v $ equals the diameter of the tree $ T $ .
Here, the length of a path is the number of edges in it, and the diameter of a tree is the maximum length of a simple path in the tree.
Input Format
The input is given from Standard Input in the following format:
> $ N $ $ u_1 $ $ v_1 $ $ u_2 $ $ v_2 $ $ \vdots $ $ u_{N-1} $ $ v_{N-1} $ $ C_1 $ $ C_2 $ $ \dots $ $ C_N $
Output Format
Print the answer.
Explanation/Hint
### Sample Explanation 1
There is $ 1 $ integer pair that satisfies the conditions: $ (1,5) $ .
### Sample Explanation 2
There are $ 2 $ integer pairs that satisfy the conditions: $ (3,6) $ and $ (4,7) $ .
### Sample Explanation 3
There are $ 2 $ integer pairs that satisfy the conditions: $ (4,5) $ and $ (5,9) $ .
### Constraints
- $ 2 \leq N \leq 2 \times 10^5 $
- $ 1 \leq u_i, v_i \leq N $
- The given graph is a tree.
- $ 1 \leq C_i \leq N $
- All input values are integers.