complete 30868.py and uncomplete 1717.py 1806.py 30869.py

This commit is contained in:
2024-09-24 21:40:59 +09:00
parent bd8d2defaa
commit 3d8097d9ca
5 changed files with 86 additions and 0 deletions

26
zeta_python/1717.py Normal file
View File

@@ -0,0 +1,26 @@
import sys
input = sys.stdin.readline
def root(P, e):
node = e
while node != P[e]:
node = P[e]
return node
if __name__ == "__main__":
N, M = map(int, input().split())
P = [i for i in range(N + 1)]
for _ in range(M):
op, a, b = map(int, input().split())
if op == 0: # Merge
if a == b:
continue
rb, ra = root(P, b), root(P, a)
if rb != ra:
P[rb] = ra
print(P)
elif op == 1: # Find
print("YES" if a == b or root(P, a) == root(P, b) else "NO")