https://school.programmers.co.kr/learn/courses/30/lessons/43162?language=python3
def solution(n, computers):
answer = 0
visited = [False for _ in range(n)]
for i in range(n):
if not visited[i]:
bfs(computers, visited, i)
answer += 1
return answer
def bfs(computers, visited, com):
visited[com] = True
q = [com]
while len(q) > 0:
curr = q.pop()
visited[curr] = True
for idx, is_connected in enumerate(computers[curr]):
if is_connected and idx != curr and not visited[idx]:
q.append(idx)
연결되어 있는 노드를 BFS를 통해 탐색하였다.