Pagini recente » Cod sursa (job #2477310) | Cod sursa (job #2561754) | Cod sursa (job #260188) | Cod sursa (job #707481) | Cod sursa (job #1039197)
#include<cstdio>
using namespace std;
int n,m,cod,i,x,y,t[100001],h[100001];
int father(int x)
{
while(t[x]!=x) x=t[x];
return x;
}
void unire(int x,int y)
{
if(h[x]==h[y])
{
h[x]++;
t[y]=x;
}
else if(h[x]<h[y])
{
t[x]=y;
}
else t[y]=x;
}
int main()
{
freopen("disjoint.in","r",stdin);
freopen("disjoint.out","w",stdout);
scanf("%d%d",&n,&m);
for(i=1;i<=m;i++) t[i]=i;
for(i=1;i<=m;i++) h[i]=1;
for(i=1;i<=m;i++)
{
scanf("%d%d%d",&cod,&x,&y);
if(cod==1) unire(father(x),father(y));
else if(father(x)==father(y)) printf("DA\n");
else printf("NU\n");
}
return 0;
}