#Q66. 「一本通 3.1 例 1」黑暗城堡
「一本通 3.1 例 1」黑暗城堡
Description
You know that Dark Castle has rooms and possible bidirectional passages that can be constructed, along with the length of each passage.
The castle is tree-shaped and satisfies the following conditions:
Let be the shortest path length between the -th room and the -st room if all passages are built;
And let be the path length between the -th room and the -st room in the actually constructed tree-shaped castle;
It is required that for all integers (), holds.
You want to know how many different castle construction schemes exist. Of course, you only need to output the result modulo .
Input Format
The first line contains two integers separated by a space, and ;
The second to the -th lines each contain three integers separated by spaces, , , , indicating that the passage between the -th room and the -th room has a length of .
Output Format
An integer: the number of different castle construction schemes modulo .
Sample 1
There are rooms and passages, where the lengths of the passages between rooms 1 and 2, 1 and 3, 1 and 4, 2 and 3, 2 and 4, and 3 and 4 are , , , , , and , respectively.
The number of different castle construction schemes modulo is .
4 6
1 2 1
1 3 2
1 4 3
2 3 1
2 4 2
3 4 1
6
Data Range and Hints
For all data, , , .