Pagini recente » Cod sursa (job #167237) | Cod sursa (job #2546047) | Cod sursa (job #1417493) | Cod sursa (job #1705773) | Cod sursa (job #2810923)
#include <iostream>
#include <vector>
#include <bitset>
using namespace std;
int nodes[100001];
int last(int i) {
while (nodes[i]) {
i = nodes[i];
}
return i;
}
int main() {
freopen("disjoint.in", "r", stdin);
freopen("disjoint.out", "w", stdout);
int nr, operations;
cin >> nr >> operations;
while (operations--) {
int cod, x, y;
cin >> cod >> x >> y;
if (cod == 1) {
nodes[last(x)] = y;
}
else {
string answer[] = { "NU\n", "DA\n" };
cout << answer[last(x) == last(y)];
}
}
return 0;
}