Pagini recente » Cod sursa (job #1584814) | Cod sursa (job #893560) | Cod sursa (job #422864) | Cod sursa (job #799033) | Cod sursa (job #1682269)
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#define N 100000
using namespace std;
int tat[N];
int findtat(int x){
while(tat[x]>=0){
x=tat[x];
}
return x;
}
int main(){
int n,m,i,t;
int x,y,temp;
freopen("disjoint.in","r",stdin);
freopen("disjoint.out","w",stdout);
scanf("%d%d",&n,&m);
for(i=0;i<n;i++){
tat[i]=-1;
}
for(i=0;i<m;i++){
scanf("%d",&t);
if(t==1){
scanf("%d%d",&x,&y);
x=findtat(x);
y=findtat(y);
if(tat[x]>tat[y]){
temp=x;
x=y;
y=temp;
}
tat[y]+=tat[x];
tat[x]=y;
}else{
scanf("%d%d",&x,&y);
if(findtat(x)==findtat(y)){
printf("DA\n");
continue;
}
printf("NU\n");
}
}
return 0;
}