Pagini recente » Cod sursa (job #352419) | Cod sursa (job #2419965) | Cod sursa (job #2283193) | Cod sursa (job #383191) | Cod sursa (job #780806)
Cod sursa(job #780806)
#include <cstdio>
using namespace std;
const int kMaxN = 100005;
int N, F[kMaxN];
inline int Find(int X) {
int Root = X;
for (; F[Root]; Root = F[Root]);
for (int Y; X != Root; Y = F[X], F[X] = Root, X = Y);
return Root;
}
inline void Merge(int X, int Y) {
X = Find(X), Y = Find(Y);
if (X != Y)
F[X] = Y;
}
int main() {
freopen("disjoint.in", "r", stdin);
freopen("disjoint.out", "w", stdout);
int M; scanf("%d %d", &N, &M);
for (; M; --M) {
int Type, X, Y;
scanf("%d %d %d", &Type, &X, &Y);
if (Type == 1)
Merge(X, Y);
if (Type == 2)
printf("%s\n", Find(X) == Find(Y) ? "DA" : "NU");
}
return 0;
}