Pagini recente » Cod sursa (job #1954775) | Cod sursa (job #1204077) | Cod sursa (job #1181044) | Cod sursa (job #2869757) | Cod sursa (job #2837550)
#include <iostream>
#include <vector>
using namespace std;
vector<int> elements;
int root(int nod) {
while (elements[nod]) {
nod = elements[nod];
}
return nod;
}
int main() {
freopen("disjoint.in", "r", stdin);
freopen("disjoint.out", "w", stdout);
int nr, operations;
cin >> nr >> operations;
elements = vector<int>(nr + 1, 0);
for (; operations; --operations) {
int cod, x, y;
cin >> cod >> x >> y;
if (cod == 1) {
elements[root(x)] = root(y);
}
else {
string result[] = { "NU\n", "DA\n" };
cout << result[root(x) == root(y)];
}
}
return 0;
}