Pagini recente » Cod sursa (job #2457711) | Cod sursa (job #940256) | Cod sursa (job #2301177) | Cod sursa (job #1956623) | Cod sursa (job #1846081)
#include <stdio.h>
#include <time.h>
#include <algorithm>
#define N 100001
using namespace std;
int i, n, m, c, x, y, T[N], H[N];
int main()
{
freopen("disjoint.in", "r", stdin);
freopen("disjoint.out", "w", stdout);
scanf("%d%d", &n, &m);
for(i = 0; i < m; i++)
{
scanf("%d%d%d", &c, &x, &y);
int tx = x, ty = y, t;
while(T[tx])
tx = T[tx];
while(T[x])
{
t = T[x];
T[x] = tx;
x = t;
}
while(T[ty])
ty = T[ty];
while(T[y])
{
t = T[y];
T[y] = ty;
y = t;
}
if(c == 2)
{
if(x == y) printf("DA\n");
else printf("NU\n");
}
else
{
if(H[x] == H[y])
{
T[y] == x;
H[x] == H[y] + 1;
}
if(H[x] < H[y])
T[x] = y;
else
T[y] = x;
}
}
return 0;
}