Pagini recente » Cod sursa (job #1968104) | Cod sursa (job #1430082) | Cod sursa (job #226273) | Cod sursa (job #2871049) | Cod sursa (job #2636456)
#include <fstream>
using namespace std;
ifstream fin("disjoint.in");
ofstream fout("disjoint.out");
int t[100005], n, m, x, y, cod;
int root(int x) {
if(!t[x]) return x;
t[x] = root(t[x]);
return t[x];
}
void Union(int x, int y) {
int rx = root(x);
int ry = root(y);
if(rx == ry) return;
t[rx] = ry;
}
int main () {
fin >> n >> m;
while(m--) {
fin >> cod >> x >> y;
if(cod == 1) Union(x, y);
else {
if(root(x) == root(y)) fout << "DA\n";
else fout << "NU\n";
}
}
}