from collections import deque
def bfs(start_node, graph):
queue = deque([start_node])
visited = set([start_node])
while queue:
curr_node = queue.popleft()
for next_node in graph[curr_node]:
if next_node not in visited:
visited.add(next_node)
queue.append(next_node)
return -1
def solution():
graph = {
'A': ['B', 'C'],
'B': ['D', 'E'],
'C': ['F'],
'D': [],
'E': ['F'],
'F': []
}
오늘의 문제는 기본적인 bfs 문제였다. 크게 어렵진 않았으나 빈출 유형이니 앞으로 꾸준히 풀어봐야겠다.
문제 풀이 전, 어떻게 풀지 미리 구상해볼 것. + 다양한 예외 상황에 대해 생각해볼 것.