Problem 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 one-person 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<=n<=50. Then follow three integers p1, p2, p3 with 1<=pi<=n denoting the starting locations of the game pieces. The colours of the arrows are given next as a m×m matrix of whitespace-separated lower-case 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
3 1 2 3
r b r
b b b
r b r
2 1 2 2
y g
g y
0

Sample Output
2
impossible

Hike on a Graph
Problem 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 one-person 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<=n<=50. Then follow three integers p1, p2, p3 with 1<=pi<=n denoting the starting locations of the game pieces. The colours of the arrows are given next as a m×m matrix of whitespace-separated lower-case 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 3 1 2 3 r b r b b b r b r 2 1 2 2 y g g y 0 Sample Output 2 impossible

20道你必须要背会的微服务面试题，面试一定会被问到

Windows可谓是大多数人的生产力工具，集娱乐办公于一体，虽然在程序员这个群体中都说苹果是信仰，但是大部分不都是从Windows过来的，而且现在依然有很多的程序员用Windows。 所以，今天我就把我私藏的Windows必装的软件分享给大家，如果有一个你没有用过甚至没有听过，那你就赚了????，这可都是提升你幸福感的高效率生产力工具哦！ 走起！???? NO、1 ScreenToGif 屏幕，摄像头和白板...

2020 年，大火的 Python 和 JavaScript 是否会被取而代之？
Python 和 JavaScript 是目前最火的两大编程语言，但是2020 年，什么编程语言将会取而代之呢？ 作者 |Richard Kenneth Eng 译者 |明明如月，责编 | 郭芮 出品 | CSDN（ID：CSDNnews） 以下为译文： Python 和 JavaScript 是目前最火的两大编程语言。然而，他们不可能永远屹立不倒。最终，必将像其他编程语言一...

AI 没让人类失业，搞 AI 的人先失业了

《java面试宝典》三 类初始化和类实例化顺序

2020年刚刚开始，就意味着离职潮高峰的到来，我身边就有不少人拿着年终奖离职了，而最让我感到意外的，是一位工作十年的数据分析师也离职了，不同于别人的主动辞职，他是被公司炒掉的。 很多人都说数据分析是个好饭碗，工作不累薪资高、入门简单又好学。然而今年34的他，却真正尝到了中年危机的滋味，平时也有不少人都会私信问我： 数据分析师也有中年危机吗？跟程序员一样是吃青春饭的吗？该怎么保证自己不被公司淘汰...

B站是个宝，谁用谁知道???? 作为一名大学生，你必须掌握的一项能力就是自学能力，很多看起来很牛X的人，你可以了解下，人家私底下一定是花大量的时间自学的，你可能会说，我也想学习啊，可是嘞，该学习啥嘞，不怕告诉你，互联网时代，最不缺的就是学习资源，最宝贵的是啥？ 你可能会说是时间，不，不是时间，而是你的注意力，懂了吧！ 那么，你说学习资源多，我咋不知道，那今天我就告诉你一个你必须知道的学习的地方，人称...

loonggg读完需要2分钟速读仅需 1 分钟大家我，我是你们的校长。前几天，搜狐的董事局主席兼 CEO 张朝阳和搜狐都上热搜了。原因很简单，就是搜狐出了“考勤新规”。一封搜狐对员工发布...

【蘑菇街技术部年会】程序员与女神共舞，鼻血再次没止住。（文末内推）

Java校招入职华为，半年后我跑路了

Python全栈 Linux基础之3.Linux常用命令
Linux对文件（包括目录）有很多常用命令，可以加快开发效率：ls是列出当前目录下的文件列表，选项有-a、-l、-h，还可以使用通配符；c功能是跳转目录，可以使用相对路径和绝对路径；mkdir命令创建一个新的目录，有-p选项，rm删除文件或目录，有-f、-r选项；cp用于复制文件，有-i、-r选项，tree命令可以将目录结构显示出来（树状显示），有-d选项，mv用来移动文件/目录，有-i选项；cat查看文件内容，more分屏显示文件内容，grep搜索内容；>、>>将执行结果重定向到一个文件；|用于管道输出。
​两年前不知如何编写代码的我，现在是一名人工智能工程师

Python实战：抓肺炎疫情实时数据，画2019-nCoV疫情地图

loonggg读完需要5分钟速读仅需 2 分钟大家好，我是你们的校长。我知道大家在家里都憋坏了，大家可能相对于封闭在家里“坐月子”，更希望能够早日上班。今天我带着大家换个思路来聊一个问题...

Spring框架|JdbcTemplate介绍

B 站上有哪些很好的学习资源?

24岁的程序员，还在未来迷茫，不知道能不能买得起房子