Pagini recente » simulare_oji2015 | Cod sursa (job #434712) | Cod sursa (job #260879) | Istoria paginii runda/aicluj13.12/clasament | Cod sursa (job #2569313)
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin ("disjoint.in");
ofstream fout ("disjoint.out");
int t[100001],n,op,x,y,m;
int Find(int x)
{
while (t[x]!=x)
x=t[x];
return x;
}
int main()
{
fin >> n >> m;
for (int i=1;i<=n;i++)
t[i]=i;
for (int i=1;i<=m;i++)
{
fin >> op >> x >> y;
x = Find(x);
y = Find(y);
if (op==1){
if (x<y)
t[y]=x;
else
t[x]=y;
}
else{
if (x==y)
fout << "DA\n";
else
fout << "NU\n";
}
}
return 0;
}