From 7eeac4c9492ad9a2c699753ba96b7d015dbdcc4b Mon Sep 17 00:00:00 2001 From: songyc macbook Date: Fri, 6 Mar 2026 22:04:28 +0900 Subject: [PATCH] baekjoon 20260306 --- code_study/Baekjoon/swift/10775.swift | 37 +++++++++++++++++++++++++++ code_study/Baekjoon/swift/2754.swift | 7 +++++ 2 files changed, 44 insertions(+) create mode 100644 code_study/Baekjoon/swift/10775.swift create mode 100644 code_study/Baekjoon/swift/2754.swift diff --git a/code_study/Baekjoon/swift/10775.swift b/code_study/Baekjoon/swift/10775.swift new file mode 100644 index 0000000..e4821f8 --- /dev/null +++ b/code_study/Baekjoon/swift/10775.swift @@ -0,0 +1,37 @@ +func solve() -> Int { + guard let G: Int = Int(readLine() ?? ""), + let P: Int = Int(readLine() ?? "") + else { return 0 } + + var root: [Int] = Array(0...G) + + func find(_ x: Int) -> Int { + if x != root[x] { + root[x] = find(root[x]) + } + return root[x] + } + + func union(_ x: Int, _ y: Int) { + root[find(y)] = find(x) + } + + var ans: Int = 0 + + for _ in 0..