#P1527D. MEX Tree
MEX Tree
Description
You are given a tree with nodes, numerated from to . For each between and , inclusive, you have to count the number of unordered pairs , , such that the MEX of all the node labels in the shortest path from to (including end points) is .
The MEX of a sequence of integers is the smallest non-negative integer that does not belong to the sequence.
The first line contains a single integer () — the number of test cases.
The first line of each test case contains a single integer ().
The next lines of each test case describe the tree that has to be constructed. These lines contain two integers and () denoting an edge between and ().
It is guaranteed that the given edges form a tree.
It is also guaranteed that the sum of for all test cases does not exceed .
For each test case, print integers: the number of paths in the tree, such that the MEX of all the node labels in that path is for each from to .
Input
The first line contains a single integer () — the number of test cases.
The first line of each test case contains a single integer ().
The next lines of each test case describe the tree that has to be constructed. These lines contain two integers and () denoting an edge between and ().
It is guaranteed that the given edges form a tree.
It is also guaranteed that the sum of for all test cases does not exceed .
Output
For each test case, print integers: the number of paths in the tree, such that the MEX of all the node labels in that path is for each from to .
Note
- In example case ,
- For , there is path that is from to as .
- For , there are paths that is from to as and to as .
- For , there is path that is from to as .
- For , there is path that is from to as
- For , there is path that is from to as .
- In example case ,
- For , there are no such paths.
- For , there are no such paths.
- For , there is path that is from to as .