# 네트워크 - 프로그래머스
def dfs(x, computers, visited):
if visited[x] == 1:
return
visited[x] = 1
for nx in range(len(computers)):
if not visited[nx] and computers[x][nx] == 1: # 연결은 되어있는데, 방문을 안했을 경우
dfs(nx, computers, visited)
def solution(n, computers):
cnt = 0
visited = [0] * (n)
while not set(visited) == {1}:
dfs(visited.index(0), computers, visited)
cnt += 1
return cnt