Pagini recente » Cod sursa (job #968079) | Cod sursa (job #2134849) | Cod sursa (job #2532741) | Cod sursa (job #1887760) | Cod sursa (job #1142344)
#include <cstdio>
using namespace std;
int h[100005],t[100005];
inline int find(int x)
{
while(t[x]!=x)
x=t[x];
return x;
}
inline void unifica(int x,int y)
{
if (h[x]>h[y])
t[y]=x;
else
if (h[x]==h[y])
{
++h[x];
t[y]=x;
}
else
t[x]=y;
}
int main()
{
freopen("disjoint.in","r",stdin);
froepen("disjoint.out","w",stdout);
int n,m,x,y,tx,ty,a;
register int i;
scanf("%d%d",&n,&m);
for(i=1; i<=n; ++i)
{
t[i]=i;
h[i]=1;
}
for(i=1; i<=m; ++i)
{
scanf("%d%d%d",&a,&x,&y);
tx=find(x);
ty=find(y);
if (a==1){
if (tx!=ty)
unifica(tx,ty);
}
else
{
if (tx==ty)
printf("DA\n");
else
printf("NU\n");
}
}
return 0;
}