Pagini recente » Cod sursa (job #120884) | Cod sursa (job #3852) | Cod sursa (job #2017303) | Cod sursa (job #2204069) | Cod sursa (job #1344968)
#include <iostream>
#include <fstream>
#define maxim 100001
using namespace std;
int n,m;
int p[maxim];
int parent(int x)
{
int aux=x;
while( aux != p[aux])
{
aux = p[aux];
p[x] = aux;
}
return aux;
}
int main()
{
freopen("disjoint.in","r",stdin);
freopen("disjoint.out","w",stdout);
scanf("%d %d",&n,&m);
int tip,x,y;
for(int i=1;i<=n;i++)
p[i]=i;
for(int i=1;i<=m;i++)
{scanf("%d %d %d",&tip,&x,&y);
if(tip==1)
p[parent(x)]=parent(y);
else if(tip==2)
{
int z=(parent(x)==parent(y));
if(z)
printf("DA\n");
else
printf("NU\n");
}
}
return 0;
}