Pagini recente » Cod sursa (job #2370162) | Cod sursa (job #2685297) | Cod sursa (job #125349) | Cod sursa (job #2680292) | Cod sursa (job #2214411)
#include <fstream>
using namespace std;
ifstream in("disjoint.in");
ofstream out("disjoint.out");
const int MAXN = 1e5;
const int MAXM = 1e5;
int n, m;
int tata[MAXN + 1];
int find_root(int nod) {
if (tata[nod] == 0)
return nod;
return tata[nod] = find_root(tata[nod]);
}
void join(int x, int y) {
tata[find_root(y)] = find_root(x);
}
bool check(int x, int y) {
if (find_root(x) == find_root(y))
return 1;
return 0;
}
int main() {
in >> n >> m;
for (int i = 1; i <= m; ++ i) {
int tip, x, y;
in >> tip >> x >> y;
if (tip == 1) {
join(x, y);
}
if (tip == 2) {
if (check(x, y))
out << "DA\n";
else
out << "NU\n";
}
}
return 0;
}