Pagini recente » Cod sursa (job #1817273) | Cod sursa (job #1785761) | Cod sursa (job #2257495) | Cod sursa (job #198034) | Cod sursa (job #547293)
Cod sursa(job #547293)
#include <cstdio>
#define file_in "disjoint.in"
#define file_out "disjoint.out"
int i,x,y,t1,t2,tip,tata[101000],n,m;
int father(int x){
if (tata[x]!=x)
tata[x]=father(tata[x]);
return tata[x];
}
void unite(int i, int j){
tata[i]=j;
}
int main(){
freopen(file_in,"r",stdin);
freopen(file_out,"w",stdout);
scanf("%d %d", &n, &m);
for (i=1;i<=n;++i) tata[i]=i;
while(m--){
scanf("%d %d %d", &tip, &x, &y);
t1=father(x);
t2=father(y);
if (tip==1){
unite(t1,t2);
}
else{
if (t1==t2)
printf("DA\n");
else
printf("NU\n");
}
}
return 0;
}