Skip to content

Commit a30b613

Browse files
committed
[백준] 안전영역 / 실버 1 / 50분
https://www.acmicpc.net/problem/2468
1 parent 77269f4 commit a30b613

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import sys
2+
3+
input = sys.stdin.readline
4+
from collections import deque
5+
6+
N = int(input())
7+
graph = [list(map(int, input().split())) for _ in range(N)]
8+
high = 0
9+
10+
for i in range(N):
11+
for j in range(N):
12+
if graph[i][j] > high:
13+
high = graph[i][j]
14+
15+
dx, dy = [0, 0, -1, 1], [-1, 1, 0, 0]
16+
queue = deque()
17+
18+
19+
def bfs(i, j, high):
20+
queue.append((i, j))
21+
visited[i][j] = 1
22+
23+
while queue:
24+
x, y = queue.popleft()
25+
26+
for i in range(4):
27+
nx = dx[i] + x
28+
ny = dy[i] + y
29+
30+
if nx < 0 or nx >= N or ny < 0 or ny >= N:
31+
continue
32+
33+
if graph[nx][ny] > high and visited[nx][ny] == 0:
34+
visited[nx][ny] = 1
35+
queue.append((nx, ny))
36+
37+
38+
result = 0
39+
for k in range(high):
40+
visited = [[0] * N for _ in range(N)]
41+
ans = 0
42+
43+
for i in range(N):
44+
for j in range(N):
45+
if graph[i][j] > k and visited[i][j] == 0:
46+
bfs(i, j, k)
47+
ans += 1
48+
49+
if result < ans:
50+
result = ans
51+
52+
print(result)

0 commit comments

Comments
 (0)