#P5351. Ruri Loves Maschera
Ruri Loves Maschera
Description
The world in Ruri’s novel has cities and roads, with no multiple edges or self-loops. Among these roads, the magic value of the -th road is .
As the Queen of the Night Demons, Ruri decides to tour the entire dark world. Each time, she randomly chooses a city as the starting point, and ends at some city after passing through at least roads and at most roads. She never goes back along the same road during the tour. If the magic values of the roads she passes through in one tour are in order, then she gains a magic value of .
Now Ruri wants to know: after trying all valid tour routes, what is the total sum of the magic values she gains?
Note that the path from to and the path from to are considered two different paths.
Input Format
The first line contains three integers .
The next lines each contain three integers , indicating that there is a road between node and node with magic value .
Output Format
Output the total sum of the magic values she gains.
5 2 3
1 2 2
2 3 2
3 4 4
4 5 5
40
Hint
Constraints:
For of the testdata, .
For another of the testdata, .
For another of the testdata, .
For another of the testdata, .
For of the testdata, , , and .
Translated by ChatGPT 5
京公网安备 11011102002149号