def DFS(i, n, computers, visited):
visited[i] = 1
for j in range(n):
if visited[j] == 0 and computers[i][j] == 1:
DFS(j, n, computers, visited)
def solution(n, computers):
answer = 0
visited = [0] * n
for i in range(n):
if visited[i] == 0:
DFS(i, n, computers, visited)
answer += 1
return answer
DFS를 활용해 다음 문제를 해결할 수 있다.