Pagini recente » Cod sursa (job #2551277) | Cod sursa (job #1492198)
#include <cstdio>
using namespace std;
int n,m,i,j,x,y,cod,t[100010],A[100010],B[100010];
int main()
{
freopen("disjoint.in","r",stdin);
freopen("disjoint.out","w",stdout);
scanf("%d%d",&n,&m);
for(i=1;i<=n;i++)
t[i] = i;
for(;m;m--)
{
scanf("%d%d%d",&cod,&x,&y);
A[1] = x; i = 1;
B[1] = y; j = 1;
while(x-t[x])
{
x = t[x];
A[++i] = x;
}
while(y-t[y])
{
y = t[y];
B[++j] = y;
}
if(cod == 1)
y = x;
else x == y ? printf("DA\n") : printf("NU\n");
for(;i;i--)t[A[i]] = x;
for(;j;j--)t[B[j]] = y;
}
return 0;
}