Pagini recente » Cod sursa (job #2059360) | Cod sursa (job #1238698) | Cod sursa (job #1188952) | Cod sursa (job #728731) | Cod sursa (job #233770)
Cod sursa(job #233770)
#include <stdio.h>
int A[100000];
int go(int x)
{
if (A[x]==0) return x;
else go(A[x]);
}
int main()
{
FILE *in = fopen("disjoint.in","r");
FILE *out = fopen("disjoint.out","w");
int n,m,o,x,y;
fscanf(in,"%d%d",&n,&m);
while (m)
{
m--;
fscanf(in,"%d%d%d",&o,&x,&y);
if (o==1) A[y]=x;
else
if (go(x)==go(y)) fprintf(out,"DA\n");
else fprintf(out,"NU\n");
}
}