Pagini recente » Cod sursa (job #1808329) | Cod sursa (job #1390708) | Cod sursa (job #381325) | Cod sursa (job #1750962) | Cod sursa (job #1166200)
#include <cstdio>
#include <cstring>
#define NMax 100001
using namespace std;
int n, m, tree_set[NMax], i, query, x, y, child1, child2;
int main()
{
freopen("disjoint.in", "r", stdin);
freopen("disjoint.out", "w", stdout);
memset(tree_set, -1, sizeof(tree_set));
scanf("%d%d", &n, &m);
for (i=1; i<=m; i++) {
scanf("%d%d%d", &query, &x, &y);
if (query==1) {
child1=x;
while (tree_set[child1] > 0)
child1=tree_set[child1];
child2=y;
while (tree_set[child2] > 0)
child2=tree_set[child2];
if (tree_set[child1] <= tree_set[child2]) {
tree_set[child2]=child1;
tree_set[child1]--;
}
else {
tree_set[child1]=child2;
tree_set[child2]--;
}
}
else {
child1=x;
while (tree_set[child1] > 0)
child1=tree_set[child1];
child2=y;
while (tree_set[child2] > 0)
child2=tree_set[child2];
if (child1 == child2)
printf("DA\n");
else
printf("NU\n");
}
}
return 0;
}