Pagini recente » Cod sursa (job #2745655) | Cod sursa (job #303406) | Cod sursa (job #1126888) | Cod sursa (job #1754999) | Cod sursa (job #2845282)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("disjoint.in");
ofstream fout("disjoint.out");
const int NMAX = 1e5;
int sef[NMAX + 1];
int findd(int x) {
if(sef[x] == x)
return x;
return (sef[x] = findd(sef[x]));
}
void unionn(int x, int y){
int sefx, sefy;
sefx = findd(x);
sefy = findd(y);
sef[sefx] = sefy;
}
int main() {
int n, q;
fin >> n >> q;
for(int i = 1; i <= n; i++)
sef[i] = i;
while(q--) {
int caz, x, y;
fin >> caz >> x >> y;
if(caz == 1) {
unionn(x, y);
} else {
if(findd(x) == findd(y)) {
fout << "DA";
} else {
fout << "NU";
}
fout << '\n';
}
}
return 0;
}