#P2126. Mzc家中的男家丁

Mzc家中的男家丁

Description

mzc is very rich (just kidding). He has nn male servants. Now mzc wants to gather them all together (for reasons unknown). Given the communication times between mzc and the male servants, please compute the total time needed to call each of them (counting repeated uses). It is guaranteed that everyone can be called.

Input Format

The first line contains a number nn, indicating there are nn male servants.
The second line contains a number mm, indicating there are mm communication routes.
Then follow mm lines, each with three numbers ai,bi,cia_i, b_i, c_i, meaning that the time needed for communication between the aia_i-th male servant (or mzc) and the bib_i-th male servant (or mzc) is cic_i (bidirectional). Here, aia_i or bi=0b_i = 0 denotes mzc.

Output Format

One line with a single number sumsum, representing the total time required to call each of them.

5
12
0 2 15
2 3 20
3 5 13
1 3 29
0 1 30
2 4 21
0 3 23
5 1 48
0 4 17
0 5 27
1 2 43
2 5 41

94

Hint

Constraints: 1n23001\le n\leq2300, 1m4×1051\le m\leq4\times10^5.

Translated by ChatGPT 5