| Baozii Cup 3 |
|---|
| Finished |
You are given a tree $$$T$$$ consisting of $$$n$$$ vertices labeled from $$$1$$$ to $$$n$$$, rooted at $$$1$$$. A pair of vertices $$$(u,v)$$$ is called valid if and only if $$$u \ne v$$$, $$$u \ne 1$$$, and $$$u$$$ is not an ancestor$$$^{\text{∗}}$$$ of $$$v$$$.
For a valid pair $$$(u,v)$$$, define $$$f(u,v)$$$ as follows:
Find the sum of $$$f(u,v)$$$ over all valid pairs $$$(u,v)$$$.
$$$^{\text{∗}}$$$An ancestor of vertex $$$v$$$ is any vertex on the simple path from $$$v$$$ to the root, including the root, but not including $$$v$$$. The root has no ancestors.
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). The description of the test cases follows.
The first line of each test case contains an integer $$$n$$$ ($$$2 \le n \le 2 \cdot 10^5$$$), representing the number of vertices in $$$T$$$.
The $$$i$$$-th of the next $$$n-1$$$ lines contains two integers $$$u_i$$$ and $$$v_i$$$ ($$$1 \le u_i,v_i \le n$$$, $$$u_i \ne v_i$$$), representing an edge in $$$T$$$. It is guaranteed that the edges form a valid tree.
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
For each test case, output an integer representing the sum of $$$f(u,v)$$$ over all valid pairs $$$(u,v)$$$.
521 231 22 331 21 361 22 33 42 55 681 22 32 44 55 61 77 8
15665163
| Name |
|---|


