baekjoon 20260326
This commit is contained in:
parent
bbff86fc50
commit
38ed2c8f91
28
code_study/Baekjoon/ts/10775.ts
Normal file
28
code_study/Baekjoon/ts/10775.ts
Normal file
@ -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<P; i++) {
|
||||
const p = find(gi[i]);
|
||||
|
||||
if(p === 0) break;
|
||||
|
||||
union(p, p-1);
|
||||
ans++;
|
||||
}
|
||||
|
||||
console.log(ans);
|
||||
2
code_study/Baekjoon/ts/3765.ts
Normal file
2
code_study/Baekjoon/ts/3765.ts
Normal file
@ -0,0 +1,2 @@
|
||||
export {};
|
||||
console.log(require("fs").readFileSync(0).toString().trim());
|
||||
Loading…
x
Reference in New Issue
Block a user