
ZOJ Problem Set  3304
In a prison, there are R*C rooms, and there are N prisoners in it, each in a room. For example: (R=5, C=6, N=7, 'P' means prisoner, '.' means empty) ...... ..P... .PPP.. ..P..P .....P On the first day, all the prisoners do not know each other, so a prisoner can only enter the rooms connected to his own which are empty. Two rooms are connected only when they share a wall. R\C 123456 1 ...... 2 ..P... 3 .PPP.. 4 ..P..P 5 .....P in this case, the (R3,C3) one can't go anywhere, but the others can go to any place marked with '.', they can even get out of the prison. On the second day, all the prisoners can't find a way to get out of the prison (out of the R*C area) are so disappointed so they kill themselves and turn to be ghosts. ('G' means ghost) ...... ..P... .PGP.. ..P..P .....P On the third day, all the prisoners alive know about the story about ghosts and are so scared that they decide to escape from the prison, so they make their rooms not only connected to the rooms sharing a wall with theirs, but also to the rooms diagonal adjacent. Of course, all the prisoners won't go into a room with a ghost. On the Fourth day, the officer in the prison feels something uncommon, so he puts a guard in each empty room. Now, the prisoners can only enter the rooms adjacent to theirs which with a prisoner in it. ('X' means a guard) XXXXXX XXPXXX XPGPXX XXPXXP XXXXXP On the Fifth day, all the prisoners make a group with all the prisoners whose rooms they can arrive and get ready for the escape. ('1' means group 1, '2' means group 2) XXXXXX XX1XXX X1G1XX XX1XX2 XXXXX2 On the Sixth day, the guards are so tired and they go home to sleep. Each group of prisoners get out of the prison finally. ...... ...... ...... ...... ...... Above is the story of prison break, however, of all the groups, what is the greatest number of prisoners in a group? Input The input contains multiple test cases(no more than 20 test cases). Each test case contains three parts: 1 Two integers R(1<= R <= 1000), C(1<= C <=1000) as mentioned above. 2 R rows each with C characters, the description of the prison on the first day. '.' means empty, 'P' means prisoner. 3 an empty line. Process to the endoffile. Output For each test case print a single line that contains answer. Sample Input 5 6 ...... ..P... .PPP.. ..P..P .....P 5 6 PPPP.P ....P. ...... ...... PPPP.P Sample Output 4 6 Author: CHAO, Jiansong Source: ZOJ Monthly, February 2010 