Card Captor Hanbyul
Time limit1sMemory limit1024 MB
Find the shortest route from vertex 1 that visits all N card vertices in a directed graph, where a vertex can be entered only if its power is at most the cards held.
- Level
Medium6 of 10
- Topics
- Graph, Shortest path, Dynamic programming
- Solved
- No attempts yet
Problem
One day, Hanbyul, who was living an ordinary life, became a magical girl. Growing stronger as a magical girl, Hanbyul decided to defeat the executives of the evil organization "Bogy." However, since Hanbyul is not skilled at magic, Hanbyul first decided to collect all "Stardust Cards," which allow anyone with magic power to use magic.
Hanbyul's region can be represented as a directed graph with vertices and edges. The vertices are numbered from to , and each edge has a fixed length. Hanbyul starts at vertex . The "Stardust Cards" are placed one each on target vertices. Hanbyul gets one card the first time Hanbyul visits each target vertex. After learning that Hanbyul collects "Stardust Cards," Bogy placed one executive on every vertex. To avoid interference from Bogy, Hanbyul must only travel through vertices where the executive's power is less than or equal to the number of cards Hanbyul holds. If Hanbyul holds cards and wants to move to a vertex, the executive's power there must be at most , regardless of whether a card is on that vertex.
Find the minimum travel distance of Hanbyul's route so that Hanbyul can collect the cards quickly. Hanbyul stops moving immediately after collecting all "Stardust Cards."