Pagini recente » Cod sursa (job #1610717) | Cod sursa (job #1433673) | Cod sursa (job #917643) | Cod sursa (job #1389249) | Cod sursa (job #295541)
Cod sursa(job #295541)
#include <stdio.h>
int t[100005],F;
inline void output(int x){if (x)printf("DA\n");else printf("NU\n");}
void down(int x){
if (t[x]==x){F=x;return;}
down(t[x]);
t[x]=F;
}
void join(int x,int y){
down(x);down(y);t[t[y]]=t[x];
}
void check(int x,int y){
down(x);down(y);
output((t[x]==t[y]));
}
int main(){
freopen("disjoint.in","r",stdin);
freopen("disjoint.out","w",stdout);
int N,M,T,x,y,i;
scanf("%d %d",&N,&M);
//preprocesare
for (i=1;i<=N;++i)t[i]=i;
//
for (; M; --M){
scanf("%d %d %d",&T,&x,&y);
if (T==1)join(x,y);
else check(x,y);
}
return 0;
}