Problem A
Völundarhús
Languages
en
is
Once again the students of The University of Iceland turn their minds towards the annual design competition. This year the robots have to get through a labyrinth, but unlike previous years the robots are not allowed to know what the track looks like ahead of time. Since the ones designing the contest don’t want to be too hard on the contestants they have decided to make sure the robots can’t travel in a circle while traversing the maze. They have also made sure that the initial maze is solvable, i.e. there is a path from the starting position to the goal. Guðmundur is now preparing to design his own robot and has devised a plan for how it will find its way through the labyrinth. When the robot comes to an intersection it will choose a random path it has not traversed earlier. If the robot finds itself in a dead end it will use its memory of traversed paths to find the shortest known path to a previous intersection with unexplored paths. The robot will then follow this calculated path and can then resume the previous loop of randomly exploring unexplored paths. The robot will stop exploring once it reaches the goal or when it finds itself back at the starting position with no paths left unexplored. You will now be given the labyrinth, the starting point and the goal. The competition consists of a number of rounds and in each round one path in the labyrinth is closed, for that round only. Your job is to look at each round and deduce whether the robot will make its way to the goal eventually and if so how long it will take on average.
Input
The first line of the input contains an integer,
Output
One line for each round, ‘Kemst ekki’ (means can’t make it
in Icelandic) if the robot won’t always finish the course,
otherwise the average time it takes the robot to finish the
course. The answer is accepted if the absolute or relative
error from the correct answer is within
Sample Input 1 | Sample Output 1 |
---|---|
3 1 2 1 1 3 1 2 1 2 |
1 Kemst ekki |
Sample Input 2 | Sample Output 2 |
---|---|
5 1 2 10 1 3 5 3 4 5 3 5 2 3 1 3 4 |
12 17 Kemst ekki |