atcoder#ABC221F. [ABC221F] Diameter set
[ABC221F] Diameter set
Score : points
Problem Statement
Given is a tree with vertices. The vertices are numbered , , , , and for each , the -th edge connects Vertex and Vertex . Let be the diameter of the tree. Find the number, modulo , of ways to choose two or more of the vertices and paint them red so that all distances between two red vertices are .
Here, the distance between two vertices is the minimum number of edges that must be traversed to travel from one vertex to the other, and the diameter of the tree is the maximum distance between two vertices.
Constraints
- All values in input are integers.
- The given graph is a tree.
Input
Input is given from Standard Input in the following format:
Output
Print the answer.
5
1 2
1 3
1 4
4 5
2
The given tree has five vertices and a diameter of . There are just two pairs of vertices whose distance is : and , so there are two ways to paint the tree to satisfy the condition: and . Note that painting does not satisfy the condition since the distance between Vertex and Vertex is .
4
1 2
1 3
1 4
4
The diameter is , and the four ways to paint the tree to satisfy the condition are: , , , .