Pagini recente » Cod sursa (job #1927776) | Cod sursa (job #2602542) | Cod sursa (job #2963446) | Cod sursa (job #3167304) | Cod sursa (job #1039251)
#include <cstdio>
using namespace std;
int t[100001],h[100001];
int findset(int x)
{
while (t[x]!=x)
x=t[x];
return x;
}
void unionset(int x,int y)
{
//x si y sunt radacini
if (h[x]==h[y])
{
h[x]++;
t[y]=x;
}
else
if (h[x]<h[y])
t[x]=y;
else
t[y]=x;
}
int main()
{
int n,op,i,x,y,tip;
freopen("disjoint.in","r",stdin);
freopen("disjoint.out","w",stdout);
scanf("%d%d",&n,&op);
for (i=1;i<=n;i++)
t[i]=i;
for (i=1;i<=op;i++)
{
scanf("%d%d%d",&tip,&x,&y);
if (tip==1)
unionset(x,y);
else
if (findset(x)==findset(y))
printf("DA\n");
else
printf("NU\n");
}
return 0;
}