function solution(n, computers) {
let graph=Array.from({length:n}, ()=>[])
for (let i=0;i<n;i++){
for (let j=0;j<n;j++){
if (computers[i][j]===1){
graph[i].push(j)
}
}
}
let visited=new Array(n).fill(false);
let answer=0;
for (let t=0;t<n;t++){
if (visited[t]===false){
answer++;
}
let next=graph[t];
while(next.length){
let current=next.shift();
if (visited[current]===false){
visited[current]=true;
next=[...next, ...graph[current]]
}
}
}
return answer;
}