#include <string>
#include <vector>
#include <stdio.h>
#include <queue>
using namespace std;
int visited[201] = {0,};
queue<int> q;
int solution(int n, vector<vector<int>> computers) {
int answer = 0;
int comCnt = computers.size();
for(int i = 0;i<computers.size();i++){
if(visited[i] == 1) continue;
answer+= 1;
q.push(i);
visited[i] = 1;
while(!q.empty()){
int idx = q.front();q.pop();
for(int j = 0;j<comCnt;j++)
{
if(computers[idx][j] == 1 && visited[j] == 0){
q.push(j); visited[j] = 1;
}
}
}
}
return answer;
}
카테고리 없음