# BOJ - 2589 - 보물섬

Updated:

```
import sys
from collections import deque
def BFS(Map, i, j, R, C):
dx = [0, 0, 1, -1]
dy = [1, -1, 0, 0]
Q = deque()
Q.append((i, j, 0))
Check = [[False] * C for _ in range(R)]
Check[i][j] = True
distance = 0
while Q:
x, y, dist = Q.popleft()
for d in range(4):
nx, ny = x + dx[d], y + dy[d]
if 0 <= nx < R and 0 <= ny < C:
if Map[nx][ny] == 'L' and Check[nx][ny] is False:
Q.append((nx, ny, dist + 1))
Check[nx][ny] = True
distance = max(dist + 1, distance)
return distance
def solution():
R, C = map(int, sys.stdin.readline().split())
Map = []
for _ in range(R):
Map.append(list(str(sys.stdin.readline().strip())))
ret = 0
for i in range(R):
for j in range(C):
if Map[i][j] == 'L':
ret = max(ret, BFS(Map, i, j, R, C))
print(ret)
solution()
```

https://www.acmicpc.net/problem/2589

## Leave a comment