Fastest Speedrun
Time limit5sMemory limit512 MB
Given n levels with per-item clear times and a shortcut item for each, find the minimum total time to beat all levels, where beating level i grants item i.
- Level
Medium7 of 10
- Topics
- Graph, Minimum spanning tree
- Solved
- No attempts yet
Problem
The classic video game "Prince of Python" has levels, numbered from 1 to . You want to speedrun the game by finishing all levels as fast as possible. You may beat the levels in any order.
You enter each level with one of magical items. At the start, you only have item 0 in your inventory. When you beat a level, you keep the item with the same number as that level. For example, after finishing level 5, you obtain the Gauntlet of 5 Fingers, which you can equip from then on instead of the Sword of 0 Damage you start with.
The time to beat a level depends on the item you bring into it. Higher-numbered items are stronger, so when playing by the rules, using a higher-numbered item is never slower than using a lower-numbered one.
Each level also has a shortcut left in by the developers. The shortcut for a level is triggered by using one specific item in an unconventional way. Using the shortcut finishes the level in a time that is no greater than the time for any other item.
What is the minimum total time needed to beat all of the levels?
Input
The input consists of:
- One line with an integer (), the number of levels.
- lines describing the levels.
The -th line starts with two integers and (, ), the shortcut item for level and the completion time for level when using the shortcut. The rest of the line has integers (), where is the completion time for level when playing by the rules with item .
Output
Output the minimum time needed to beat all of the levels, in any order.