-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbj_4963.py
More file actions
47 lines (32 loc) · 816 Bytes
/
bj_4963.py
File metadata and controls
47 lines (32 loc) · 816 Bytes
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
45
46
47
# 백준 4963번 DFS 코드
import sys
sys.setrecursionlimit(int(1e5))
input = sys.stdin.readline
def sol(x, y):
if x < 0 or x >= h or y < 0 or y >= w:
return False
if area[x][y] == 1:
area[x][y] = 2
sol(x+1, y)
sol(x-1, y)
sol(x, y-1)
sol(x, y+1)
sol(x-1, y-1)
sol(x-1, y+1)
sol(x+1, y-1)
sol(x+1, y+1)
return True
return False
while True:
w, h = map(int, input().split())
if w == h == 0:
break
area = []
for i in range(h):
area.append(list(map(int, input().split())))
count = 0
for i in range(h):
for j in range(w):
if sol(i,j):
count += 1
print(count)