깊이 우선 탐색
-
DFS와 BFS (백준 1260번)파이썬/알고리즘 2023. 7. 9. 18:34
from collections import deque, defaultdict import sys read = sys.stdin.readline def dfs(info, v, visited): if visited[v] == True: return visited[v] = True print(v, end=' ') for next_ in info[v]: if not visited[next_]: dfs(info, next_, visited) def bfs(info, start, visited): dq = deque([start]) visited[start] = True while dq: v = dq.popleft() print(v, end=' ') for next_ in info[v]: if not visited..