#abc221f. F - Diameter set
F - Diameter set
Score : points
问题描述
给定一棵包含 个顶点的树。这些顶点依次编号为 , , , ,对于每个 ,第 条边连接顶点 和顶点 。令 为这棵树的直径。求满足以下条件的不同红色顶点选择方案的数量(模 ):选择两个或更多的顶点涂成红色,使得任意两个红色顶点之间的距离均为 。
这里,两个顶点之间的距离是指从一个顶点到另一个顶点必须经过的最短边数,树的直径则是任意两个顶点之间最大距离。
以上为通义千问 qwen-max 翻译,仅供参考。
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.
Sample Input 1
5
1 2
1 3
1 4
4 5
Sample Output 1
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 .
Sample Input 2
4
1 2
1 3
1 4
Sample Output 2
4
The diameter is , and the four ways to paint the tree to satisfy the condition are: , , , .
update @ 2024/3/10 09:45:33