Pagini recente » Cod sursa (job #3354621) | Cod sursa (job #3334001) | Cod sursa (job #1398114) | Cod sursa (job #725753) | Cod sursa (job #3304114)
#include <bits/stdc++.h>
using namespace std;
int parent[100005];
int find(int x) {
if (parent[x] == x)
return x;
return find(parent[x]);
}
void join(int x, int y) { parent[find(x)] = find(y); }
int main() {
ifstream cin("disjoint.in");
ofstream cout("disjoint.out");
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; i++)
parent[i] = i;
int type, x, y;
while (m--) {
cin >> type >> x >> y;
if (type == 1) {
join(x, y);
} else {
if (find(x) == find(y))
cout << "DA\n";
else
cout << "NU\n";
}
}
}