Pagini recente » Cod sursa (job #28089) | Cod sursa (job #90049) | Cod sursa (job #2316668) | Cod sursa (job #1283266) | Cod sursa (job #2847724)
#include <bits/stdc++.h>
#define NMAX 100000
using namespace std;
ifstream in("disjoint.in");
ofstream out("disjoint.out");
int v[NMAX + 1];
int find(int x) {
if(v[x] == x)
return x;
return (v[x] = find(v[x]));
}
void unite(int x, int y){
int Setx, Sety;
Setx = find(x);
Sety = find(y);
v[Setx] = Sety;
}
int main() {
int n, q;
in >> n >> q;
for(int i = 1; i <= n; i++)
v[i] = i;
while(q--) {
int caz, x, y;
in >> caz >> x >> y;
if(caz == 1) {
unite(x, y);
} else {
if(find(x) == find(y)) {
out << "DA";
} else {
out << "NU";
}
out << '\n';
}
}
return 0;
}