The Crocodile's Underground City
Time limit2sMemory limit256 MB
Find the minimum guaranteed escape time from room 0 to any exit room when a gatekeeper blocks one corridor at each room before Chulsoo moves.
- Level
Hard8 of 10
- Topics
- Graph, Shortest path, Greedy, Dynamic programming
- Solved
- No attempts yet
Problem
Archaeologist Chulsoo was exploring a mysterious underground city of crocodiles when he sensed danger and had to flee.
The underground city has rooms, numbered to . There are corridors, each connecting two distinct rooms, and each corridor takes a certain amount of time to traverse. At most one corridor connects any given pair of rooms. Among the rooms, are exit rooms from which one can escape immediately. Chulsoo starts in room (which is not an exit room) and wants to reach any exit room as fast as possible.
The crocodile gatekeeper tries to stop Chulsoo. At any single moment the gatekeeper may block exactly one corridor; blocking a new corridor reopens the previously blocked one. Concretely, when Chulsoo is about to leave a room, the gatekeeper may block one of the corridors attached to that room. Chulsoo then chooses one of the unblocked corridors and moves. Once Chulsoo has entered a corridor, it cannot be blocked until he finishes crossing it. After he arrives in another room, the gatekeeper may again block one corridor (including the one he just used), and so on.
Chulsoo fixes an escape plan in advance, specifying what to do upon reaching each room. If room is an exit room, he escapes immediately and needs no plan. Otherwise, the plan for room must be one of:
- From room , first move to room ; if that corridor is blocked, move to room instead.
- Room is never reached under this plan, so no action is specified.
Note that under some plans (for example, if Chulsoo walks in a cycle) the gatekeeper can make escape impossible forever. A plan is called good if it guarantees that, no matter what the gatekeeper does, Chulsoo escapes in finite time. For a good plan, the smallest time such that Chulsoo is guaranteed to have escaped after regardless of the gatekeeper's strategy is called the plan's escape time.
The input describes the following values.
- — the number of rooms, numbered to .
- — the number of corridors, numbered to .
- Each corridor () connects room
R[i][0]and roomR[i][1], and takesL[i]() time to traverse. At most one corridor connects any pair of rooms. - — the number of exit rooms ().
P[0], …, P[K-1]— the exit room numbers. They are all distinct, and room is not among them.
Output the minimum escape time over all good plans. You may assume every non-exit room has at least corridors attached, and that every input admits a good plan with .
Input
The first line contains , , and . Each of the next lines contains R[i][0], R[i][1], and L[i] for one corridor. Each of the following lines contains one exit room number P[i].
Output
Print the minimum escape time on a single line.