From 38ed2c8f912088fbeb1a49b372d18e35b2f8c40d Mon Sep 17 00:00:00 2001 From: songyc macbook Date: Thu, 26 Mar 2026 23:16:40 +0900 Subject: [PATCH] baekjoon 20260326 --- code_study/Baekjoon/ts/10775.ts | 28 ++++++++++++++++++++++++++++ code_study/Baekjoon/ts/3765.ts | 2 ++ 2 files changed, 30 insertions(+) create mode 100644 code_study/Baekjoon/ts/10775.ts create mode 100644 code_study/Baekjoon/ts/3765.ts 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