Pagini recente » Cod sursa (job #1345128) | Cod sursa (job #538126) | Cod sursa (job #669188) | Cod sursa (job #911598) | Cod sursa (job #3260723)
import sys
nmax = int(1e5 + 5)
fin = open("disjoint.in", "r")
fout = open("disjoint.out", "w")
n, m = map(int, fin.readline().split())
tata = list(range(nmax))
h = [1] * nmax
def Radacina(nod):
if tata[nod] == nod:
return nod
else:
r = Radacina(tata[nod])
tata[nod] = r
return r
def Unire(a, b):
a = Radacina(a)
b = Radacina(b)
if h[a] < h[b]:
tata[a] = b
h[b] += h[a]
else:
tata[b] = a
h[a] += h[b]
for _ in range(m):
c, x, y = map(int, fin.readline().split())
if c == 1:
if Radacina(x) != Radacina(y):
Unire(x, y)
else:
if Radacina(x) != Radacina(y):
fout.write("NU\n")
else:
fout.write("DA\n")
fin.close()
fout.close()