The Color Game

In this problem, you will get introduced to a new game called the “Color Game”. In the N-cell (3 ≤ N ≤ 100) color game, there are N cells each having a different color. For simplicity, we will assume that the colors are represented by unique positive integers ranging from 1 to N. Each cell has at most one edge (directed) of each color running to another or even the same cell. This is a two-player game and it consists of two phases. In the first phase one of the players plays and in the second phase plays the other. Suppose player 1 plays in the first phase. At the beginning, player 2 selects three cells N1, N2 and N3, and places two tokens in N1 and N2 respectively. Now he challenges player 1 to move any one of the tokens to cell N3 in as few moves as possible. In each move only one of the two tokens can be moved. A token can move from the current cell to an adjacent cell only following an edge of the same color as that of the cell the other token is in. At the end of the phase, player 2 must prove that there is a way of moving one of the tokens to cell N3 otherwise he will lose. The second phase is similar to the first one except that the players are now reversed. The player solving the problem in fewer moves wins the game. Now, given the description of the network of cells and the values of N1, N2 and N3, you are asked to write a program to determine the minimum number of moves required to moves any of the tokens to cell N3. Input The input file consists of several data blocks. Each data block describes a game. The first line of a data block contains an integer N (3 ≤ N ≤ 100) representing the number of cells. Then follows N lines of N integers each. The j-th integer in the i-th line (1 ≤ i,j ≤ N) gives the cell number to which cell i is connected by an edge of color j. If cell i does not have an edge of color j, then this integer has a value ‘0. The last line of the data block contains the three integers: N1, N2 and N3. The input file terminates with a zero for N. Output For each game in the input first output the game number followed by the minimum number of moves required to solve it. Print the line ‘Destination is Not Reachable !’ if the problem is not solvable. Print a blank line after the outputs for each data set. Sample Input 5 25355 02130 01334 15225 54050 531 6 005401 601344

2/2 505026 310455 322464 125200 326 0 Sample Output Game #1 Destination is Not Reachable ! Game #2 Minimum Number of Moves = 6