Pagini recente » Cod sursa (job #2977375) | Cod sursa (job #1139059) | Cod sursa (job #2667033) | Cod sursa (job #1515262) | Cod sursa (job #1182379)
#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[x] = tata(y);
} else {
if (tata(x) == tata(y)) {
printf("DA\n");
} else {
printf("NU\n");
}
}
}
return 0;
}