-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1717번.py
More file actions
41 lines (34 loc) · 712 Bytes
/
1717번.py
File metadata and controls
41 lines (34 loc) · 712 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#집합의 표현
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10000)
N, M = map(int, input().split())
parent = [0] * (N+1)
def find(a):
if a == parent[a]:
return a
else:
parent[a] = find(parent[a])
return parent[a]
def union(a, b):
a = find(a)
b = find(b)
if a != b:
parent[b] = a
def checkSame(a, b):
a = find(a)
b = find(b)
if a == b:
return True
return False
for i in range(0, N+1):
parent[i] = i
for i in range(M):
question, a, b = map(int, input().split())
if question == 0:
union(a, b)
else:
if checkSame(a, b):
print("YES")
else:
print("NO")