Pagini recente » Cod sursa (job #273074) | Cod sursa (job #1250880) | Cod sursa (job #37175) | Cod sursa (job #542483) | Cod sursa (job #1166192)
#include <cstdio>
#define NMax 100001
using namespace std;
int n, m, tree_set[NMax], i, query, x, y, child1, child2;
int main()
{
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];
tree_set[child1]=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;
}