Pagini recente » Cod sursa (job #3334638) | Cod sursa (job #2212183) | Cod sursa (job #255743) | Cod sursa (job #2533519) | Cod sursa (job #662871)
Cod sursa(job #662871)
#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;
}