2666. Three bad friends

单点时限: 2.0 sec

内存限制: 256 MB

HH,LL and TT are three bad friends. But their houses are very near from each other. They want to put some barriers so that their houses couldn’t connect together.

“H” on the map indicates HH’s house,”L” indicates LL’s house ,”T” indicates TT’s house,”.” indicates free space and you could put a barrier on it. .”X” indicate a barrier.

If there are three or more free spaces connect to one’s house,the house is not save. No one will live on an unsave house.And I sure the three boys must live on save houses.

Now, tell you the information of the map, please help the three Poor boys to calculate the minimum barriers they need to put so that their houses couldn’t connect together.

输入格式

The first line with two numbers n and m(0<n,m<10) stands for the size of the map;then n lines follow ,each line with m characters.There are exact one “H”,one “L” and one “T”.

And I ensure the number of “X” will not exceed 5.

There are no more then 30 cases.

输出格式

Output the minimum barriers they need to put.If there is no way to separate them ,just output “Impossible”.

样例

Input
5 5
.....
H....
XX.XX
.....
.LXT.
3 5
LX.X.
..HT.
.XXX.
Output
1
Impossible

3 人解决,4 人已尝试。

12 份提交通过,共有 39 份提交。

8.1 EMB 奖励。

创建: 14 年,11 月前.

修改: 6 年,11 月前.

最后提交: 3 年,8 月前.

来源: N/A

题目标签