링크 : https://school.programmers.co.kr/learn/courses/30/lessons/43162
(DFS)
#include <string>
#include <vector>
#include <cstring>
using namespace std;
bool visited[201];
void DFS(int cur, int n, vector<vector<int>> computers){
visited[cur] = true;
for(int i = 0; i < n; i ++){
if(!visited[i] && computers[cur][i] == 1)
DFS(i, n, computers);
}
}
int solution(int n, vector<vector<int>> computers) {
int answer = 0;
memset(visited, false, sizeof(visited));
for(int i = 0; i < n; i ++){
if(!visited[i]){
DFS(i, n, computers);
answer ++;
}
}
return answer;
}