Pagini recente » Cod sursa (job #2931977) | Cod sursa (job #572342) | Cod sursa (job #1450212) | Cod sursa (job #1212810) | Cod sursa (job #276186)
Cod sursa(job #276186)
#include<stdio.h>
#define nmax 100010
long a[nmax], n, m;
FILE *f, *g;
long find(long x)
{ if(a[x]==x)
return x;
else
find(a[x]);
}
int main()
{ long i, x, y, c, rx, ry;
f=fopen("disjoint.in", "r");
g=fopen("disjoint.out", "w");
fscanf(f, "%ld%ld", &n, &m);
for(i=1; i<=n; i++)
a[i]=i;
for(i=1; i<=m; i++)
{ fscanf(f, "%ld%ld%ld", &c, &x, &y);
rx=find(x);
ry=find(y);
if(c==1)
a[rx]=ry;
else
if(rx==ry) fprintf(g, "DA\n");
else fprintf(g, "NU\n");
}
return 0;
}