#P981H. K Paths
K Paths
No submission language available for this problem.
Description
You are given a tree of vertices. You are to select (not necessarily distinct) simple paths in such a way that it is possible to split all edges of the tree into three sets: edges not contained in any path, edges that are a part of exactly one of these paths, and edges that are parts of all selected paths, and the latter set should be non-empty.
Compute the number of ways to select paths modulo .
The paths are enumerated, in other words, two ways are considered distinct if there are such () and an edge that the -th path contains the edge in one way and does not contain it in the other.
The first line contains two integers and () — the number of vertices in the tree and the desired number of paths.
The next lines describe edges of the tree. Each line contains two integers and (, ) — the endpoints of an edge. It is guaranteed that the given edges form a tree.
Print the number of ways to select enumerated not necessarily distinct simple paths in such a way that for each edge either it is not contained in any path, or it is contained in exactly one path, or it is contained in all paths, and the intersection of all paths is non-empty.
As the answer can be large, print it modulo .
Input
The first line contains two integers and () — the number of vertices in the tree and the desired number of paths.
The next lines describe edges of the tree. Each line contains two integers and (, ) — the endpoints of an edge. It is guaranteed that the given edges form a tree.
Output
Print the number of ways to select enumerated not necessarily distinct simple paths in such a way that for each edge either it is not contained in any path, or it is contained in exactly one path, or it is contained in all paths, and the intersection of all paths is non-empty.
As the answer can be large, print it modulo .
Samples
Note
In the first example the following ways are valid:
- ,
- ,
- ,
- ,
- ,
- ,
- .
In the second example , so all paths are valid.
In the third example, the answer is , so it was taken modulo , don't forget it!