diff --git a/code_study/Baekjoon/ts/10775.ts b/code_study/Baekjoon/ts/10775.ts new file mode 100644 index 0000000..cf20a2d --- /dev/null +++ b/code_study/Baekjoon/ts/10775.ts @@ -0,0 +1,28 @@ +export {}; +const input = require("fs").readFileSync(0).toString().trim().split("\n").map(Number); +const [G, P]: number[] = [input[0], input[1]] +const gi: number[] = input.slice(2); + +let roots: number[] = Array.from({length : G+1}, (_, i) => i); + +const find = (g: number): number => { + if(roots[g] !== g) roots[g] = find(roots[g]); + return roots[g]; +} + +const union = (a: number, b: number) => { + roots[find(a)] = find(b); +} + +let ans: number = 0; + +for(let i=0; i