Skip to content

Commit bc0d625

Browse files
committed
[22.02.27] 1388 - dfs
1 parent 4a81cde commit bc0d625

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

Diff for: Python_BOJ_2022/1388.py

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# 바닥장식
2+
n, m = map(int, input().split())
3+
graph = [list(map(str, input())) for _ in range(n)]
4+
5+
# 수평을 체크
6+
def dfs_hori(x, y):
7+
if 0 <= x < n and 0 <= y < m:
8+
if graph[x][y] == "-":
9+
graph[x][y] = "x"
10+
dfs_hori(x, y - 1)
11+
dfs_hori(x, y + 1)
12+
return
13+
else:
14+
return
15+
16+
# 수직을 체크
17+
def dfS_vert(x, y):
18+
if 0 <= x < n and 0 <= y < m:
19+
if graph[x][y] == "|":
20+
graph[x][y] = "x"
21+
dfS_vert(x - 1, y)
22+
dfS_vert(x + 1, y)
23+
return
24+
else:
25+
return
26+
27+
cnt = 0
28+
for i in range(n):
29+
for j in range(m):
30+
if graph[i][j] == "-":
31+
dfs_hori(i, j)
32+
cnt += 1
33+
elif graph[i][j] == "|":
34+
dfS_vert(i, j)
35+
cnt += 1
36+
37+
print(cnt)

0 commit comments

Comments
 (0)