Pagini recente » Borderou de evaluare (job #186368) | Borderou de evaluare (job #1108472) | Borderou de evaluare (job #2587106) | Borderou de evaluare (job #1807254) | Cod sursa (job #3001088)
#include <bits/stdc++.h>
using namespace std;
ifstream f ("disjoint.in");
ofstream g ("disjoint.out");
const int NMax = 100001;
int T[NMax+1];
int Find (int i) {
if (T[i] == 0)
return i;
return T[i] = Find(T[i]);
}
inline void Union(int cx, int cy) {
T[cy] = cx;
}
int main()
{
int N, M, op, x, y, cx, cy;
f >> N >> M;
while (M--) {
f >> op >> x >> y;
cx = Find(x);
cy = Find(y);
if (op == 1) {
if (cx != cy) {
Union(cx, cy);
}
}
else {
if (cx == cy)
g << "DA\n";
else
g << "NU\n";
}
}
return 0;
}