diff --git a/code_study/Baekjoon/python/4299.py b/code_study/Baekjoon/python/4299.py new file mode 100644 index 0000000..adedbef --- /dev/null +++ b/code_study/Baekjoon/python/4299.py @@ -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))) \ No newline at end of file diff --git a/code_study/Baekjoon/ts/20040.ts b/code_study/Baekjoon/ts/20040.ts new file mode 100644 index 0000000..193eac5 --- /dev/null +++ b/code_study/Baekjoon/ts/20040.ts @@ -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); \ No newline at end of file