Pagini recente » Cod sursa (job #925321) | Cod sursa (job #3285531) | Cod sursa (job #2847854) | Cod sursa (job #1324646) | Cod sursa (job #1830413)
#include<iostream>
#include<fstream>
#include<algorithm>
#include<set>
#include<climits>
#include<cstring>
#include<map>
#include<queue>
#include<vector>
#include<bitset>
#define mp make_pair
#define pb push_back
#define ff(i, x, n) for (int i = x; i <= n; ++i)
#define dd(i) cout << i <<'\n'
#define READ_FROM_FILE
using namespace std;
int tt(int x);
int n, m, t[100005], h[100005];
int main(){
#ifdef READ_FROM_FILE
ifstream in("disjoint.in");
#define cin in
#endif
ofstream out("disjoint.out");
int x, y, cod;
cin >> n >> m;
ff(i, 1, n) {
t[i] = i;
h[i] = 1;
}
while (m--) {
cin >> cod >> x >> y;
if (cod == 1) {
if (h[t[x]] > h[t[y]]) {
t[t[y]] = t[x];
}
if (h[t[x]] < h[t[y]]) {
t[t[x]] = t[y];
}
if (h[t[x]] == h[t[y]]) {
t[t[y]] = t[x];
++h[t[x]];
}
} else {
if (tt(x) == tt(y)) {
out << "DA\n";
} else {
out << "NU\n";
}
}
}
}
int tt(int x) {
while(t[t[x]] != t[x]) {
t[x] = t[t[x]];
}
return t[x];
}