python-for-coding-test
python-for-coding-test copied to clipboard
151p dfs 질문드립니다
n, m = map(int, input().split())
graph = [] for i in range(n): graph.append(list(map(int, input())))
def dfs(x, y): if x <= -1 or x >= n or y <= -1 or y >= n: return False if graph[x][y] == 0:
graph[x][y] = 1
dfs(x - 1, y)
dfs(x, y - 1)
dfs(x + 1, y)
dfs(x, y + 1)
return True
return False
result = 0 for i in range(n): for j in range(m):
if dfs(i, j) == True:
result += 1
print(result)
위 처럼 코드를 책보면서 작성했는데 값이 달라요 이상하게 깃 허브에 올라와있는 코드를 복붙하고 주석을 없앤건 정상 작동이 되는데 제가 직접 코딩한거하고 값이 다른데 왜 이런건가요??