You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import Foundation
func solution1717(){letnm=readLine()!.components(separatedBy:.whitespaces).map({Int($0)! })varparent=[Int](0...nm[0])func find(_ b:Int)->Int{
if b !=parent[b]{parent[b]=find(parent[b])}returnparent[b]}func union(_ a:Int, _ b:Int){leta=find(a)letb=find(b)
if a >= b {parent[a]= b
}else{parent[b]= a
}}
for _ in 1...nm[1]{letcal=readLine()!.components(separatedBy:.whitespaces).map({Int($0)! })leta=cal[1]letb=cal[2]
if cal[0]==0{union(a, b)}else{
if find(a)==find(b){print("YES")}else{print("NO")}}}}
The text was updated successfully, but these errors were encountered:
💬 문제
https://www.acmicpc.net/problem/1717
💬 Idea
💬 풀이
The text was updated successfully, but these errors were encountered: