Pagini recente » Cod sursa (job #2557435) | Istoria paginii runda/hjghj | Cod sursa (job #1140899) | Cod sursa (job #824465) | Cod sursa (job #2953178)
#include <bits/stdc++.h>
using namespace std;
ifstream f("disjoint.in");
ofstream g("disjoint.out");
const int N = 1e5 + 5;
int q, n, c, x, y, graf[N], getroot(int);
int main()
{
f >> n >> q;
for (int i = 1; i <= n; i++) graf[i] = i;
for (; q; q--){
f >> c >> x >> y;
x = getroot(x);
y = getroot(y);
if (c == 1) graf[x] = y;
else g << (x == y ? "DA\n" : "NU\n");
}
return 0;
}
int getroot(int nod){
if (graf[nod] == nod) return nod;
else return graf[nod] = getroot(graf[nod]);
}