2668. Three good friends

单点时限: 2.0 sec

内存限制: 256 MB

FF,JJ and QQ are three good friends. But their house are very far away form each others.Their want to build a road so that their houses could connect together.

“F” on the map indicate FF’s house,”J” indicates JJ’s house ,”Q” indicates QQ’s house,”.” indicates there could build road on it. “X” indicates a barrier,there can’t build road.

Now, tell you the information of the map,please help three lovely girls to calculate the minimum cost to build the road;

输入格式

The first line with two numbers n and m(0<n,m<=100)stands for the size of the map;then n lines follow ,each line with m characters.There are exact one “J”,one “Q” and one “F”.

输出格式

If could build please output the minimum cost;others output”Impossible”;

样例

Input
3 3
F.X
...
J.Q
3 3
F..
..X
JXQ
Output
2
Impossible

6 人解决,13 人已尝试。

8 份提交通过,共有 36 份提交。

7.8 EMB 奖励。

创建: 15 年,3 月前.

修改: 7 年,3 月前.

最后提交: 4 年前.

来源: N/A

题目标签