๋ฐฑ์ค 2606๋ฒ
์ฝ๋
const fs = require('fs');
const input = fs.readFileSync('/dev/stdin').toString().trim().split('\n');
const N = +input.shift();
const E = +input.shift();
let graph = {};
for (let i = 1; i <= N; i++) {
graph[i] = [];
}
for (let i = 0; i < E; i++) {
const [a, b] = input[i].split(" ");
graph[a].push(b);
graph[b].push(a);
}
let checked = [];
willCheck = ['1'];
while (willCheck.length !== 0) {
const check = willCheck.shift();
if (!checked.includes(check)) {
checked.push(check);
willCheck.push(...graph[check]);
}
}
console.log(checked.length - 1);