프로그래머스 네트워크
def solution(n, computers):
d = {node:set() for node in range(n)}
for i,computer in enumerate(computers):
for j,edge in enumerate(computer):
if edge and i != j:
d[i].add(j)
answer = 0
seen = set()
queue = []
for i in range(n):
if i not in seen:
answer += 1
queue.append(i)
while queue:
com = queue.pop(0)
for node in d[com]:
if node not in seen:
seen.add(node)
queue.append(node)
return answer