Pagini recente » Cod sursa (job #1908101) | Rating vasile runcan (tranny) | Cod sursa (job #2975187) | Cod sursa (job #3286180) | Cod sursa (job #226501)
Cod sursa(job #226501)
#include <cstdio>
#include <cstdlib>
#include <cassert>
using namespace std;
#define MAXN 100005
int N, M;
int p[MAXN];
inline int getSet(int x)
{
if (x == p[x])
return x;
return p[x] = getSet(p[x]);
}
int main()
{
freopen("disjoint.in", "rt", stdin);
freopen("disjoint.out", "wt", stdout);
assert(scanf("%d %d", &N, &M) == 2);
assert(1 <= N && N <= 100000);
assert(1 <= M && M <= 100000);
for (int i = 1; i <= N; i++)
p[i] = i;
for (int i = 0; i < M; i++)
{
int type, x, y;
assert(scanf("%d %d %d", &type, &x, &y) == 3);
assert(type == 1 || type == 2);
assert(1 <= x && x <= N);
assert(1 <= y && y <= N);
x = getSet(x);
y = getSet(y);
if (type == 1)
{
assert(x != y);
if (rand() & 1)
p[x] = y;
else
p[y] = x;
}
else
printf("%s\n", (x == y) ? "DA" : "NU");
}
return 0;
}