Pagini recente » Cod sursa (job #2182709) | Cod sursa (job #1657995) | Cod sursa (job #1160596) | Cod sursa (job #1070849) | Cod sursa (job #1133143)
/*
Keep It Simple!
*/
#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#endif
#include<stdio.h>
#define MaxN 100005
int n,m, Tree[MaxN], Rang[MaxN];
void Init()
{
for (int i = 1; i <= n; i++)
Tree[i] = i;
}
void AddToTree(int a, int b)
{
if (Rang[a] > Rang[b])
Tree[b] = a;
else
Tree[a] = b;
if (Rang[a] == Rang[b]) Rang[b]++;
}
int Find_Root(int x)
{
int Root = x;
while (Tree[Root] != Root) Root = Tree[Root];
while (Tree[x] != x)
{
x = Tree[x];
Tree[x] = Root;
}
return Root;
}
int main()
{
freopen("disjunct.in", "r", stdin);
freopen("disjunct.out", "w", stdout);
scanf("%d%d", &n, &m);
Init();
int type, x, y;
for (int i = 1; i <= m; i++)
{
scanf("%d%d%d", &type, &x, &y);
if (type == 1)
AddToTree(x, y);
else if (type == 2)
{
if (Find_Root(x) == Find_Root(y)) printf("DA\n");
else printf("NU\n");
}
}
}