[Gold V] Title: 집합의 표현, Time: 348 ms, Memory: 72404 KB -BaekjoonHub
This commit is contained in:
30
백준/Gold/1717. 집합의 표현/README.md
Normal file
30
백준/Gold/1717. 집합의 표현/README.md
Normal file
File diff suppressed because one or more lines are too long
40
백준/Gold/1717. 집합의 표현/집합의 표현.py
Normal file
40
백준/Gold/1717. 집합의 표현/집합의 표현.py
Normal file
@@ -0,0 +1,40 @@
|
||||
import sys
|
||||
|
||||
input = sys.stdin.readline
|
||||
|
||||
n,m = map(int, input().split())
|
||||
|
||||
def union(a, b):
|
||||
a = find(a)
|
||||
b = find(b)
|
||||
if a!=b:
|
||||
lst[b] = a
|
||||
|
||||
def find(a):
|
||||
if(a==lst[a]):
|
||||
return a
|
||||
else:
|
||||
lst[a] = find(lst[a])
|
||||
return lst[a]
|
||||
|
||||
def checkSame(a,b):
|
||||
a = find(a)
|
||||
b = find(b)
|
||||
if(a==b):
|
||||
return True
|
||||
return False
|
||||
|
||||
lst = []
|
||||
for i in range(1000001):
|
||||
lst.append(i)
|
||||
|
||||
for _ in range(m):
|
||||
check, a, b = map(int, input().split())
|
||||
|
||||
if check == 0:
|
||||
union(a,b)
|
||||
else:
|
||||
if checkSame(a,b):
|
||||
print("YES")
|
||||
else:
|
||||
print("NO")
|
||||
Reference in New Issue
Block a user