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..