Pagini recente » Cod sursa (job #2984815) | Cod sursa (job #3292712) | Cod sursa (job #2671038) | Cod sursa (job #2889337) | Cod sursa (job #3160703)
#include <bits/stdc++.h>
using namespace std;
ifstream in("disjoint.in");
ofstream out("disjoint.out");
int tata[100001];
int sef(int x)
{
if(tata[x]==x)
return x;
else
return tata[x]=sef(tata[x]);
}
void unire(int x,int y)
{
tata[sef(y)]=sef(x);
}
int main()
{
int n,i,cate,op,x,y;
in>>n>>cate;
for(i=1;i<=n;++i)
tata[i]=i;
for(i=1;i<=cate;++i)
{
in>>op>>x>>y;
if(op==1)
unire(x,y);
else
if(sef(x)==sef(y))
out<<"DA"<<'\n';
else
out<<"NU"<<'\n';
}
}