#1046
Unrated
OKRET
시간 제한
1s
메모리 제한
32MB
제출
0
정답
0
맞힌 사람
0
정답 비율
0.0%

문제

Author: Adrian Satja Kurdija

Mirko has been learning to drive, but he still cannot make a U-turn in a narrow street. That’s why he has decided to go practice in a town where U-turns are forbidden everywhere. This prohibition can be marked by the following sign:

Mirko has soon figured out that his ideal town must not contain dead-end streets, since it is impossible to exit such a street without a U-turn (let us assume that Mirko cannot drive in reverse either). Write a program to analyse a town map and determine whether the town is suitable for Mirko (i.e. whether the town has any dead-end streets). The town map is a table with R x C cells, where each cell is a building segment (denoted by X) or a road surface (denoted by a dot). From a road surface cell, Mirko can move to any of the surrounding four cells (up, down, left, or right), provided that it is also a road surface (i.e. not a building). Formally, we will determine that a town is free of dead-end streets if, starting from any road surface cell and going in any of the possible directions, we can return to the starting cell without making a 180 degrees turn (changing our direction to the opposite one).

입력

The first line of input contains the positive integers R and C (3 ≤ R, C ≤ 10), the dimensions of the town. Each of the next R lines contains C characters, with each character either “X” or “.”. These R x C characters represent the town map as described in the text above. At least two cells will be road surfaces, and all road surfaces will be connected (i.e. mutually reachable).

출력

The first and only line of output must contain 0 if the town is free of dead-end streets, otherwise it must contain 1.

예제 입력 1

4 3
XXX
X.X
X.X
XXX

예제 출력 1

1

예제 입력 2

5 5
XX.XX
X...X
.....
X...X
XX.XX

예제 출력 2

1

예제 입력 3

3 9
...XXX...
.X.....X.
...XXX...

예제 출력 3

0
코드 제출

코드를 제출하려면 로그인이 필요합니다.

로그인
내 제출
제출 내역이 없습니다.
맞은 사람
아직 맞은 사람이 없습니다.
난이도 투표
Unrated0명 투표
로그인 후 AC 받으면 투표할 수 있습니다.
전체 제출
제출 내역이 없습니다.