Pagini recente » Cod sursa (job #2558102) | Cod sursa (job #2706956) | Cod sursa (job #3161173) | Cod sursa (job #1807909) | Cod sursa (job #2200606)
#include <iostream>
#include <bits/stdc++.h>
#include <fstream>
using namespace std;
ifstream f("disjoint.in");
ofstream g("disjoint.out");
int m, t[100002];
inline int tata(int x)
{
while(t[x])
x=t[x];
return x;
}
inline void compresie(int x, int r)
{
int cx;
while(t[x])
{
cx=t[x];
t[x]=r;
x=cx;
}
}
int main()
{
int op, x, y, r;
f>>m>>m;
while(f>>op>>x>>y)
{
if(op==1)
{
x=tata(x);
y=tata(y);
t[x]=y;
}
else
{
r=tata(x);
compresie(x, r);
if(r==tata(y))
g<<"DA\n";
else
g<<"NU\n";
}
}
return 0;
}