Triangle Tree
시간 제한2초메모리 제한2048 MB
서로 조상 관계가 아닌 모든 정점 쌍에 대해, LCA 아래 두 거리와 삼각형을 이루는 정수 x의 개수를 모두 더한다.
문제
One day, a giant tree grew in the countryside. Little John, with his childhood eagle, decided to make it his home. Little John will build a structure on the tree with galvanized square steel. However, little did he know, he could not build what is physically impossible.
You are given a rooted tree1 containing vertices rooted at vertex . A pair of vertices is called a good pair if is not an ancestor2 of and is not an ancestor of . For any two vertices, is defined as the number of edges on the unique simple path from to , and is defined as their lowest common ancestor.
A function is defined as follows.
- If is a good pair, is the number of distinct integer values such that there exists a non-degenerate triangle3 formed by side lengths , , and .
- Otherwise, is .
You need to find the following value:
1A tree is a connected graph without cycles. A rooted tree is a tree where one vertex is special and called the root.
2An ancestor of vertex is any vertex on the simple path from to the root, including the root, but not including . The root has no ancestors.
3A triangle with side lengths , , is non-degenerate when , , .
입력
Each test contains multiple test cases. The first line contains the number of test cases (). The description of the test cases follows.
The first line of each test case contains a single integer ().
Each of the next lines contains two integers and , denoting the two vertices connected by an edge (, ).
It is guaranteed that the given edges form a tree.
It is guaranteed that the sum of over all test cases does not exceed .
출력
For each test case, output the answer on a separate line.
힌트
On the first test case, the only good pair satisfying is . Here, is , and the two distances are and .
There is only one value of for two side lengths and , which is . Therefore, the answer for the first test case is .
On the second test case, there is no good pair. Therefore, the answer for the second test case is .
On the third test case, the good pairs satisfying are as follows.
- : is , distances are and . There is only one possible value of , which is .
- : is , distances are and . There is only one possible value of , which is .
- : is , distances are and . There is only one possible value of , which is .
- : is , distances are and . There is only one possible value of , which is .
Therefore, the answer for the third test case is .