IT보안관의 공부 클라우드
[이코테 DFS]음료수 얼려먹기 본문
https://www.youtube.com/watch?v=7C9RgOcvkvo&list=PLRx0vPvlEmdAghTr5mXQxGpHjWqSz0dgC&index=3
def dfs(x,y,graph):
if x < 0 or x >= n or y < 0 or y >= m:
return
if graph[x][y] == 1:
return False
else:
graph[x][y] = 1
dfs(x-1,y,graph)
dfs(x+1,y,graph)
dfs(x,y-1,graph)
dfs(x,y+1,graph)
return True
from collections import deque
n,m = map(int,input().split())
graph=[]
cnt = 0
for i in range(n):
graph.append(list(map(int,input())))
for i in range(n):
for j in range(m):
if dfs(i,j,graph):
cnt += 1
#print(graph)
#print(n,m)
print(cnt)
'코딩 테스트 > 기타' 카테고리의 다른 글
[이코테 BFS]미로 탈출 (0) | 2022.07.03 |
---|
Comments