https://programmers.co.kr/learn/courses/30/lessons/43162
def solution(n, computers):
answer = 0
visited = [False] * n
edges = [[] for _ in range(n)]
for i in range(n):
for j in range(n):
if i != j and computers[i][j] == 1:
edges[i].append(j)
for i in range(n):
if not visited[i]:
network(i, visited, edges)
answer = answer + 1
return answer
def network(start, visited, edges):
queue = [start]
visited[start] = True
while len(queue) > 0:
vertex = queue.pop()
for next_vertex in edges[vertex]:
if not visited[next_vertex]:
queue.append(next_vertex)
visited[next_vertex] = True