#P1707D. Partial Virtual Trees
Partial Virtual Trees
Description
Kawashiro Nitori is a girl who loves competitive programming. One day she found a rooted tree consisting of vertices. The root is vertex . As an advanced problem setter, she quickly thought of a problem.
Kawashiro Nitori has a vertex set . She's going to play a game with the tree and the set. In each operation, she will choose a vertex set , where is a partial virtual tree of , and change into .
A vertex set is a partial virtual tree of a vertex set , if is a subset of , , and for all pairs of vertices and in , is in , where denotes the lowest common ancestor of vertices and on the tree. Note that a vertex set can have many different partial virtual trees.
Kawashiro Nitori wants to know for each possible , if she performs the operation exactly times, in how many ways she can make in the end? Two ways are considered different if there exists an integer () such that after operations the sets are different.
Since the answer could be very large, you need to find it modulo . It's guaranteed that is a prime number.
The first line contains two integers and (, ). It's guaranteed that is a prime number.
Each of the next lines contains two integers , (), representing an edge between and .
It is guaranteed that the given edges form a tree.
The only line contains integers — the answer modulo for .
Input
The first line contains two integers and (, ). It's guaranteed that is a prime number.
Each of the next lines contains two integers , (), representing an edge between and .
It is guaranteed that the given edges form a tree.
Output
The only line contains integers — the answer modulo for .
Note
In the first test case, when , the only possible way is:
- .
When , there are possible ways:
- ;
- ;
- ;
- ;
- ;
- .
When , there are possible ways:
- ;
- ;
- ;
- ;
- ;
- .