#P10929. 黑暗城堡

黑暗城堡

Problem Description

After successfully breaking through Lord lsp’s defenses, lqr and the group arrived beneath Lord lsp’s castle.

After Lord lsp turned evil, although he gained powerful superpowers and could use telekinesis to create buildings, his intelligence did not increase much.

Now lqr has figured out that the dark castle has NN rooms, MM bidirectional passages that can be built, and the length of each passage.

lqr knows Lord lsp well. To avoid having to think about the shortest path between two rooms every time, Lord lsp will surely build the castle as a tree.

However, to improve his moving efficiency as much as possible, Lord lsp will make the castle satisfy the following condition:

Let D[i]D[i] be the shortest path length from room ii to room 11 if all passages are built, and let S[i]S[i] be the path length from room ii to room 11 in the actually built tree-shaped castle. The requirement is that for all integers ii, S[i]=D[i]S[i]=D[i] holds.

To defeat Lord lsp, lqr wants to know how many different castle construction plans there are.

It is guaranteed that at least one feasible castle construction plan exists.

You need to output the answer modulo 23112^{31}–1.

Input Format

The first line contains two integers NN and MM.

The next MM lines each contain three integers XX, YY, and LL, indicating that a passage of length LL can be built between XX and YY.

Output Format

Output one integer, the answer modulo 23112^{31}–1.

3 3
1 2 2
1 3 1
2 3 1
2

Hint

Constraints: 2N10002 \le N \le 1000, N1MN(N1)/2N-1 \le M \le N(N-1)/2, 1L1001 \le L \le 100.

Translated by ChatGPT 5