Skip to content

Commit

Permalink
Merge pull request #76 from AlgoLeadMe/20-seongwon030
Browse files Browse the repository at this point in the history
20-seongwon030
  • Loading branch information
seongwon030 authored Jul 23, 2024
2 parents 8b757c8 + 77fbdea commit f87df67
Showing 1 changed file with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import sys
input = sys.stdin.readline

n,m = map(int,input().split())
parent = [i for i in range(n+1)]

def find(x):
if x!=parent[x]:
parent[x] = find(parent[x])
return parent[x]

def union(x,y):
x,y = find(x),find(y)
if x<y:
parent[x] = y
else:
parent[y] = x

for i in range(m):
a,b,c = list(map(int,input().split()))
if not a:
union(b,c)
else:
if find(b) == find(c):
print("YES")
else:
print("NO")

0 comments on commit f87df67

Please sign in to comment.