Pagini recente » Cod sursa (job #532700) | Cod sursa (job #1869916) | Cod sursa (job #2260241) | Cod sursa (job #927058) | Cod sursa (job #1540281)
#include <cstdio>
#include <algorithm>
#define Nmax 100002
using namespace std;
int n, m, t[Nmax], T;
int Root(int x)
{
if(!t[x])
return x;
t[x] = Root(t[x]);
return t[x];
}
void Union(int x, int y)
{
int rx = Root(x);
int ry = Root(y);
if(rx != ry)
t[rx] = ry;
}
bool B(int x, int y)
{
return Root(x) == Root(y);
}
int main()
{
int i, x, y;
freopen("disjoint.in", "r", stdin);
freopen("disjoint.out", "w", stdout);
scanf("%d %d", &n, &m);
for(i = 1; i <= m; ++ i)
{
scanf("%d %d %d", &T, &x, &y);
if(T == 1)
Union(x, y);
else
{
if(B(x,y) == 1)
printf("DA\n");
else printf("NU\n");
}
}
return 0;
}