Pagini recente » Utilizatori inregistrati la preONI 2007, Runda 1, Clasele 11-12 | Cod sursa (job #2989549) | Cod sursa (job #1477549) | Cod sursa (job #2025819) | Cod sursa (job #295533)
Cod sursa(job #295533)
#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){
t[y]=x;down(y);
}
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;
}