Pagini recente » Cod sursa (job #2566963) | Cod sursa (job #1378102) | Cod sursa (job #1737740) | Cod sursa (job #3342047) | Cod sursa (job #662869)
Cod sursa(job #662869)
#include <stdio.h>
#define max 100001
using namespace std;
int a,b,c,d,e,v[max];
int gaseste(int b)
{
if (v[b]!=b)
{
v[b]=gaseste(v[b]);
}
return v[b];
}
int main()
{
freopen("disjoint.in","r",stdin);
freopen("disjoint.out","w",stdout);
scanf("%d%d",&a,&b);
while(a--)
{
v[a]=a;
}
while(b--)
{
scanf("%d%d%d",&c,&d,&e);
if(c==1)
v[gaseste(c)]==gaseste(d);
else
{
if(gaseste(c)==gaseste(d))
printf("DA \n");
else
printf("NU \n");
}
}
fclose(stdin);
fclose(stdout);
return 0;
}