On his holiday, Josh finds himself in a kingdom with
Josh's tour guide tells him that there are also some positive number of tribes, each denoted with a positive integer, and each having a headquarter in exactly one village. No two tribes have the same headquarter. Additionally, each village is occupied by exactly one tribe - the tribe whose headquarters are the shortest distance away from the village. If there are multiple tribes with headquarters being the shortest distance away from the village, the village could be occupied by any of those tribes.
After exploring each village, Josh determines that the
Josh would like to know the number of different possible states of the kingdom. Two kingdoms states are considered different if there exists a village satisfying one of the two conditions below:
- Both kingdom states have a headquarter at that village, but the headquarters belong to different tribes.
- One kingdom state has a headquarter at that village, and the other kingdom state doesn't.
Since this number might be very large, output it modulo
Note: it is not required that the tribes present are labelled from
Constraints
All villages can be reached from all other villages by travelling along the roads.
For any two villages occupied by the same tribe
Subtask 1 [15%]
Subtask 2 [15%]
Subtask 3 [70%]
No additional constraints.
Input Specification
The first line contains two space-separated integers,
The second line contains
The
Output Specification
Output the number of possible kingdom states modulo
Sample Input
5 10
1 1 2 2 2
1 2
1 3
3 4
3 5
Sample Output
6
Explanation
For this kingdom, tribe
- Village
is equidistant to both headquarters, so it could feasibly be occupied by tribe . - Village
is closest to the headquarters located in village , which belongs to tribe . - Villages
, and are closest to the headquarters located in village , which belongs to tribe .
Comments