-
Notifications
You must be signed in to change notification settings - Fork 0
/
BOJ_2468.py
44 lines (36 loc) · 891 Bytes
/
BOJ_2468.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import sys
input = sys.stdin.readline
dire = [
[1, 0],
[-1, 0],
[0, 1],
[0, -1]
]
def dfs(y, x, i):
q = [[y, x]]
while q:
hy, hx = q.pop()
visit[hy][hx] = True
for ny, nx in dire:
next_y, next_x = ny + hy, nx + hx
if 0 <= next_y < n and 0 <= next_x < n:
if graph[next_y][next_x] > i and not visit[next_y][next_x]:
q.append([next_y, next_x])
n = int(input())
graph = []
for _ in range(n):
graph.append(list(map(int, input().split())))
ans = 1
for i in range(1, 101):
cnt = 0
visit = [[False for _ in range(n)] for _ in range(n)]
for y in range(n):
for x in range(n):
if graph[y][x] > i and not visit[y][x]:
dfs(y, x, i)
cnt += 1
if cnt == 0:
break
if ans <= cnt:
ans = cnt
print(ans)