Pagini recente » Cod sursa (job #311544) | Cod sursa (job #1610414) | pregatireoji_clasa_xi-xii | Istoria paginii utilizator/cristelnita | Cod sursa (job #3251106)
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int NMAX = 1e5;
int n, m, a, b, c;
int v[NMAX+ 2];
void reuniune(int x, int y) {
for (int i = 1; i <= n; i++) {
if (v[i] == x) v[i] = y;
}
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
#ifndef ONLINE_JUDGE
freopen("disjoint.in", "r", stdin);
freopen("disjoint.out", "w", stdout);
#endif
cin >> n >> m;
for (int i = 1; i <= n; i++) {
v[i] = i;
}
while (m--) {
cin >> a >> b >> c;
if (a == 1) {
if (v[b] != v[c]) reuniune(v[b], v[c]);
}
else {
if (v[b] == v[c]) cout << "DA\n";
else cout << "NU\n";
}
}
return 0;
}