Pagini recente » Cod sursa (job #882836) | Cod sursa (job #890781) | Cod sursa (job #2678884) | Cod sursa (job #672316) | Cod sursa (job #1220416)
#include <iostream>
#include <cstdio>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <cmath>
#include <fstream>
using namespace std;
#define inf 0xfffffff
#define MOD 1999999973
int n, m, rad[100010];
struct muchie{
int a, b, c;
};
int tata(int x) {
if (x == rad[x]) return x; {
rad[x] = tata(rad[x]);
return rad[x];
}
}
int main() {
int op, x, y;
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;
for (int i = 1; i <= m; i++) {
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;
}