Indiana Jones Among the Zombies
Time limit6sMemory limit128 MB
Every turn each zombie steps toward chamber 1 along a shortest path, and you find the first turn with more than K arrivals or confirm Indiana survives.
- Level
Medium4 of 10
- Topics
- BFS, Shortest path, Sorting
- Solved
- No attempts yet
Problem
Indiana Jones has finished his search for the Amulet of Body and Mind Control with mixed fortune. The good news is that he found the amulet. The bad news is that the labyrinth he is trapped in is full of zombies, and the amulet he planned to use against them does not work. Indiana has to fall back on the old way of fighting the undead: shooting them at close range with a Smith and Wesson revolver.
The labyrinth has chambers numbered from to . Indiana is in chamber . Each of the other chambers initially holds exactly one zombie. Chambers are connected by two-way corridors.
Every turn, each surviving zombie moves one step along a corridor to the next chamber on a shortest path from its current chamber to Indiana's chamber (chamber ). If no path leads from a zombie's chamber to Indiana's chamber, that zombie stays where it is. If a chamber has several shortest paths toward Indiana's chamber, the zombies there take the corridor that appears first in the input.
Indiana's revolver holds bullets. If at most zombies arrive in Indiana's chamber during a turn, he shoots them all. Otherwise he is eaten.
Determine whether Indiana escapes unharmed, and if not, find the turn in which he is eaten.
Input
The first line contains one natural number (), the number of test sets. The test sets follow.
The first line of each test set contains three space-separated natural numbers , , and (): is the number of chambers, the number of corridors, and the capacity of Indiana's revolver.
Each of the next lines describes one corridor as a pair of distinct natural numbers and (), meaning a two-way corridor connects chambers and . Every pair of chambers is joined by at most one corridor.
Output
For each test set, print on its own line the turn in which Indiana is eaten (the zombies make their first move on turn ), or the word hurray! if Indiana survives.