Pagini recente » Cod sursa (job #997974) | Cod sursa (job #1824762) | Cod sursa (job #1976538) | Cod sursa (job #2446124) | Cod sursa (job #1804906)
#include<cstdio>
#include<cstdlib>
#include<ctime>
int sef[100001];
int findt(int x){
if(x==sef[x])
return x;
sef[x]=findt(sef[x]);
return sef[x];
}
void uniont(int x,int y){
int a,b;
a=findt(x);
b=findt(y);
if(rand()%2==0)
sef[a]=b;
else
sef[b]=a;
}
int main(){
srand(time(0));
int n,m,i,q,x,y;
freopen("disjoint.in","r",stdin);
freopen("disjoint.out","w",stdout);
scanf("%d%d",&n,&m);
for(i=1;i<=n;i++)
sef[i]=i;
for(i=1;i<=m;i++){
scanf("%d%d%d",&q,&x,&y);
if(q==1)
uniont(x,y);
else if(findt(x)==findt(y))
printf("DA\n");
else
printf("NU\n");
}
return 0;
}