Hotels
Time limit3sMemory limit256 MB
Count triplets of distinct towns in a tree whose three pairwise distances are all equal.
- Level
Medium7 of 10
- Topics
- Tree, Dynamic programming, Combinatorics
- Solved
- No attempts yet
Problem
Byteotia has towns connected by roads of equal length. The roads form a tree.
The king wants three luxury hotels in three different towns, all at the same pairwise distance. Count how many such triplets exist.
Input
The first line contains (). Each of the next lines contains two integers and (), the endpoints of a road.
Output
Print the number of valid hotel triplets.