#P4043. [AHOI2014/JSOI2014] 支线剧情
[AHOI2014/JSOI2014] 支线剧情
Description
In the RPG that JYY is currently playing, there are storyline points, numbered to . At the -th storyline point, depending on JYY’s choices, he can go through different branching storylines to different new storyline points. If , then point is an ending of the game.
Watching a single branching storyline takes some time. JYY starts at storyline point , which is the beginning of the game. Clearly, every storyline point is reachable from point . Moreover, as the game progresses, the storyline is irreversible. Therefore, the game guarantees that starting from any storyline point, you can never return to this point again.
Due to JYY’s excessive use of modifiers, the game’s “save” and “load” features are broken. The only way to return to a previous storyline point is to quit the current game and start a new game, i.e., return to point . JYY may quit and restart at any time. Repeatedly starting new games to rewatch already seen storylines is painful, so JYY wants to minimize the total time to watch all different branching storylines.
Input Format
The first line contains a single positive integer .
Then follow lines. The -th line describes storyline point :
- The first integer is , followed by pairs of integers and , indicating that from storyline point you can go to storyline point , and watching this branching storyline takes time.
Output Format
Output a single integer on one line, the minimum total time JYY needs to watch all branching storylines.
6
2 2 1 3 2
2 4 3 5 4
2 5 5 6 6
0
0
0
24
Hint
Sample explanation:
JYY needs to restart the game times. Together with the initial playthrough, the playthroughs are:
- .
- .
- .
- .
Constraints:
For of the testdata, , , , .
Translated by ChatGPT 5
京公网安备 11011102002149号