题目
Description
“Hike on a Graph” is a game that is played on a board on which an undirected graph is drawn. The graph is complete and has all loops, i.e. for any two locations there is exactly one arrow between them. The arrows are coloured. There are three players, and each of them has a piece. At the beginning of the game, the three pieces are in fixed locations on the graph. In turn, the players may do a move. A move consists of moving one’s own piece along an arrow to a new location on the board. The following constraint is imposed on this: the piece may only be moved along arrows of the same colour as the arrow between the two opponents’ pieces.
In the sixties (“make love not war”) a oneperson variant of the game emerged. In this variant one person moves all the three pieces, not necessarily one after the other, but of course only one at a time. Goal of this game is to get all pieces onto the same location, using as few moves as possible. Find out the smallest number of moves that is necessary to get all three pieces onto the same location, for a given board layout and starting positions.
Input
The input file contains several test cases. Each test case starts with the number $n$ . Input is terminated by $n=0$ . Otherwise, $1 \leq n \leq 50$ . Then follow three integers $p_1$ , $p_2$ , $p_3$ with $1 \leq pi\leq n$ denoting the starting locations of the game pieces. The colours of the arrows are given next as a $m×m$ matrix of whitespaceseparated lowercase letters. The element mij denotes the colour of the arrow between the locations $i$ and $j$ . Since the graph is undirected, you can assume the matrix to be symmetrical.
Output
For each test case output on a single line the minimum number of moves required to get all three pieces onto the same location, or the word “impossible” if that is not possible for the given board and starting locations.
Sample Input


Sample Output


Source
University of Ulm Local Contest 2000
题意
给你 $n$ 个点 $(1 \leq n \leq 50)$ 构成的完全无向图（任意两点之间都存在边包括自己到自己的边 ），三个棋子的起始位置，再给出每个点到另一个点的或者到自己的边的颜色，有 $r,g,b$ 三种颜色，分别代表 $red,green,blue$，不是重点。一个棋子从一个点走到另一个点的要求是：从该点走到另一个点的这条边的颜色只能和另外两个棋子组成的边颜色相同 ，问你三个棋子走到同一个点最少需要多少步。
分析
按照要求进行 $bfs$ .
代码

