Pagini recente » Cod sursa (job #32695) | Cod sursa (job #1100648) | Cod sursa (job #1465662) | Cod sursa (job #2790270) | Cod sursa (job #1347362)
#include <cstdio>
#define DIM 100003
using namespace std;
FILE *fin=freopen("disjoint.in","r",stdin);
FILE *fout=freopen("disjoint.out","w",stdout);
int Father[DIM];
int n, m;
void Read()
{
scanf("%d %d", &n, &m);
for(int i = 1; i <= n; ++i)
Father[i] = i;
}
int Group(int x)
{
for(; x != Father[x]; x = Father[x]);
return x;
}
void Unite(int x, int y)
{
Father[Group(x)] = Group(y);
}
void Solve()
{
int op, x, y;
for(int i = 1; i <= m; ++i)
{
scanf("%d %d %d ", &op, &x, &y);
if(op == 1)
Unite(x, y);
else
{
if( Group(x) == Group(y) )
printf("DA\n");
else
printf("NU\n");
}
}
}
int main()
{
Read();
Solve();
return 0;
}