Pagini recente » Cod sursa (job #388641) | Cod sursa (job #2742815) | Cod sursa (job #1192537) | Cod sursa (job #2517997) | Cod sursa (job #1039128)
#include<cstdio>
using namespace std;
int n,m,x,y,o;
int t[100005],h[100005];
int findset(int x)
{
while(t[x]!=x)
x=t[x];
return x;
}
void unitset(int x,int y)
{
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()
{
freopen("disjoint.in","r",stdin);
freopen("disjoint.out","w",stdout);
scanf("%d%d",&n,&m);
int i;
for(i=1;i<=n;i++)
{
t[i]=i;
h[i]=1;
}
for(i=1;i<=m;i++)
{
scanf("%d%d%d",&o,&x,&y);
if(o==1)
{
unitset(findset(x),findset(y));
}
else
{
if(findset(x)==findset(y)) printf("DA\n");
else printf("NU\n");
}
}
return 0;
}