Pagini recente » Istoria paginii runda/pregatire_oni2011_runda2/clasament | Cod sursa (job #2528640) | Cod sursa (job #418038) | Cod sursa (job #270950) | 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;
}