Pagini recente » Cod sursa (job #139390) | Cod sursa (job #790267) | Cod sursa (job #915609) | Cod sursa (job #2706219) | Cod sursa (job #2293581)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("disjoint.in");
ofstream fout("disjoint.out");
const int N = 100010;
int n,m,i,rx,ry,cod,x,y,T[N],getRoot(int);
int main()
{
fin>>n>>m;
for(i=1;i<=n;i++)
T[i]=i;
for(;m;m--)
{
fin>>cod>>x>>y;
rx=getRoot(x);
ry=getRoot(y);
if(cod==1)
T[rx]=ry;
else
{
if(rx==ry)
fout<<"DA\n";
else fout<<"NU\n";
}
}
return 0;
}
int getRoot(int nod)
{
if(T[nod]==nod)return nod;
T[nod]=getRoot(T[nod]);
return T[nod];
}