#P4337. [ZJOI2018] 线图
[ZJOI2018] 线图
Description
Today, Kelian wants to make a problem related to graph theory. On an undirected graph , we can perform some interesting transformations, such as taking the dual or the complement. These operations often bring new life to classical problems. For example, connectivity of the complement graph and shortest paths on the complement graph are both very interesting problems.
Recently, Kelian learned a new transformation: taking the line graph of the original graph. For an undirected graph , its line graph is also an undirected graph:
- Its vertex set has size , and each vertex corresponds uniquely to an edge of the original graph.
- There is an edge between two vertices if and only if the two corresponding edges in the original graph share an endpoint (note that there are no self-loops). The figure below shows a simple example: the left figure is the original graph, and the right figure is its line graph. Vertex corresponds to edge in the original graph, vertex corresponds to , vertex corresponds to , and vertex corresponds to .

After some initial exploration, Kelian found that the properties of line graphs are much more complicated than those of complement graphs. A notable point is that the complement of the complement returns to the original graph, while is not equal to in most cases, and in many cases the number of vertices and edges grows rapidly.
Therefore, Kelian wants to start from the simplest case, namely computing the number of vertices of (where means taking the line graph of times). Unfortunately, even this problem is too hard for her, so she weakens it. She gives a tree with nodes and asks you to compute the number of vertices in .
Input Format
The first line contains two integers , denoting the number of vertices in the tree and the number of times to take the line graph.
The next lines each contain two integers , representing an edge of the tree.
Output Format
Output a single integer: the answer modulo .
5 3
1 2
2 3
2 5
3 4
5
Hint
As shown below, the left figure is the original tree, the middle figure is , and the right figure is . is not shown here, but since has 5 edges, has 5 vertices.


Translated by ChatGPT 5
京公网安备 11011102002149号