#P4043. [AHOI2014/JSOI2014] 支线剧情

    ID: 2992 远端评测题 1000ms 125MiB 尝试: 3 已通过: 1 难度: 8 上传者: 标签>2014各省省选网络流江苏安徽上下界网络流费用流

[AHOI2014/JSOI2014] 支线剧情

Description

In the RPG that JYY is currently playing, there are NN storyline points, numbered 11 to NN. At the ii-th storyline point, depending on JYY’s choices, he can go through different branching storylines to KiK_i different new storyline points. If Ki=0K_i = 0, then point ii is an ending of the game.

Watching a single branching storyline takes some time. JYY starts at storyline point 11, which is the beginning of the game. Clearly, every storyline point is reachable from point 11. 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 11. 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 NN.

Then follow NN lines. The ii-th line describes storyline point ii:

  • The first integer is KiK_i, followed by KiK_i pairs of integers bi,jb_{i,j} and ti,jt_{i,j}, indicating that from storyline point ii you can go to storyline point bi,jb_{i,j}, and watching this branching storyline takes ti,jt_{i,j} 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 33 times. Together with the initial playthrough, the 44 playthroughs are:

  • 1241 \to 2 \to 4.
  • 1251 \to 2 \to 5.
  • 1351 \to 3 \to 5.
  • 1361 \to 3 \to 6.

Constraints:

For 100%100\% of the testdata, N300N \le 300, 0Ki500 \le K_i \le 50, 1ti,j3001 \le t_{i,j} \le 300, Ki5000\sum K_i \le 5000.

Translated by ChatGPT 5