Pagini recente » Cod sursa (job #731820) | Cod sursa (job #1466266) | Cod sursa (job #480663) | Cod sursa (job #2577304) | Cod sursa (job #1182385)
#include <cstdio>
#include <string>
#include <algorithm>
using namespace std;
int rad[100010], n, m, op, x, y;
int tata(int x) {
if (x == rad[x]) return x; else {
rad[x] = tata(rad[x]);
return rad[x];
}
}
int main()
{
freopen("disjoint.in","r",stdin);
freopen("disjoint.out","w",stdout);
scanf("%d %d", &n, &m);
for (int i = 1; i <= n; i++) rad[i] = i;
while (m--) {
scanf("%d %d %d", &op, &x, &y);
if (op == 1) {
rad[tata(x)] = tata(y);
} else {
if (tata(x) == tata(y)) {
printf("DA\n");
} else {
printf("NU\n");
}
}
}
return 0;
}