Pagini recente » Cod sursa (job #404798) | Profil Anca8 | Statistici Cristian Nicoleta (toxic) | Monitorul de evaluare | Cod sursa (job #1034828)
#include <algorithm>
#include <iostream>
#include <fstream>
using namespace std;
int tata[100010];
int inline root(int nod) {
if (tata[nod] != nod)
tata[nod] = root(tata[nod]);
return tata[nod];
}
int main() {
ifstream cin("disjoint.in");
ofstream cout("disjoint.out");
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; i++)
tata[i] = i;
for (; m; m--) {
int tip, x, y;
cin >> tip >> x >> y;
if (tip == 1) {
if (root(x) != root(y))
tata[root(x)] = root(y);
}
else cout << ((root(x) == root(y))? "DA\n" : "NU\n");
}
return 0;
}