Pagini recente » Cod sursa (job #2192368) | Cod sursa (job #3332477) | Cod sursa (job #3331386) | Cod sursa (job #2024356) | Cod sursa (job #662874)
Cod sursa(job #662874)
#include <stdio.h>
#define max 100001
using namespace std;
int a,b,c,d,e,v[max];
int gaseste(int x)
{
if (v[x]!=x)
{
v[x]=gaseste(v[x]);
}
return v[x];
}
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(d)]==gaseste(e);
else
{
if(gaseste(d)==gaseste(e))
printf("DA \n");
else
printf("NU \n");
}
}
fclose(stdin);
fclose(stdout);
return 0;
}