Triples
Time limit7sMemory limit512 MB
Given a tree with up to 100,000 vertices in each of up to 20 test cases, count the unordered triples of vertices that are all at the same positive distance from each other.
- Level
Medium7 of 10
- Topics
- Tree, Dynamic programming, Combinatorics
- Solved
- No attempts yet
Problem
You are given a tree, that is, a connected undirected graph with no cycles. For every two vertices , let denote the length (the number of edges) of the unique simple path between and . Count all the (unordered) triples such that .

Input
The first line contains the number of test cases (). The descriptions of the test cases follow.
The first line of each test case contains the number of vertices (). Each of the next lines contains two integers (), meaning there is an edge between vertices and .
Output
For each test case, output one integer: the number of triples in question.