baekjoon 20251225
This commit is contained in:
parent
59fb800c04
commit
6c5c41c27e
1
code_study/Baekjoon/python/4299.py
Normal file
1
code_study/Baekjoon/python/4299.py
Normal file
@ -0,0 +1 @@
|
|||||||
|
print(-1 if (lambda x : x[0] < x[1] or ((x[0] + x[1]) % 2 != 0 and (x[0] - x[1]) % 2 != 0))(s := list(map(int,input().split()))) else ' '.join((lambda x : list([str((x[0]+x[1])//2), str((x[0]-x[1])//2)]))(s)))
|
||||||
36
code_study/Baekjoon/ts/20040.ts
Normal file
36
code_study/Baekjoon/ts/20040.ts
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
export {};
|
||||||
|
const input = require("fs").readFileSync(0).toString().trim().split('\n');
|
||||||
|
const [n, m]: number[] = input[0].split(" ").map(Number);
|
||||||
|
|
||||||
|
let parent: number[] = Array.from({length: n}, (_, i) => i);
|
||||||
|
let rank: number[] = new Array(n).fill(0);
|
||||||
|
|
||||||
|
const find = (x: number): number => {
|
||||||
|
if(x !== parent[x]) return parent[x] = find(parent[x]);
|
||||||
|
return parent[x];
|
||||||
|
}
|
||||||
|
|
||||||
|
const union = (x: number, y: number): boolean => {
|
||||||
|
x = find(x);
|
||||||
|
y = find(y);
|
||||||
|
|
||||||
|
if(x===y) return false;
|
||||||
|
|
||||||
|
if(rank[x] < rank[y]) [x, y] = [y, x];
|
||||||
|
|
||||||
|
parent[y] = x;
|
||||||
|
if(rank[x] === rank[y]) rank[x] += 1;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
let ans: number = 0;
|
||||||
|
for(let i=1; i<=m; i++) {
|
||||||
|
let [u, v]: number[] = input[i].split(" ").map(Number);
|
||||||
|
if(!union(u, v)) {
|
||||||
|
ans = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(ans);
|
||||||
Loading…
x
Reference in New Issue
Block a user