Pagini recente » Borderou de evaluare (job #1397024) | Cod sursa (job #314219) | Cod sursa (job #339451) | Borderou de evaluare (job #2539041) | Cod sursa (job #1012183)
#include <cstdio>
FILE*f=fopen("disjoint.in","r");
FILE*h=fopen("disjoint.out","w");
int t[100001];
int tata(int x){
if ( t[x]==0 )return x;
else return tata(t[x]);
}
char *ver(int x,int y){
if ( tata(x)==tata(y) )return "DA";
return "NU";
}
int main()
{
int n;
fscanf(f,"%d%d",&n,&n);
for ( int i=1;i<=n;++i ){
int k,x,y;
fscanf(f,"%d%d%d",&k,&x,&y);
if ( k==1 ){
t[tata(y)]=tata(x);
}
if ( k==2 ){
fprintf(h,"%s\n",ver(x,y));
}
}
return 0;
}