Pagini recente » Cod sursa (job #2701409) | Cod sursa (job #2645177) | Cod sursa (job #2178855) | Cod sursa (job #1820081) | Cod sursa (job #2144213)
#include <cstdio>
using namespace std;
const int NMAX = 100005;
int father[NMAX];
int n,m;
int searchfor(int x)
{
while(x!= father[x])
x = father[x];
return x;
}
void Solve()
{
int a,b,task;
scanf("%d %d",&n,&m);
for(int i = 1 ; i<= n ; i++)
{
father[i] = i;
}
for(int i = 0 ; i < m ; i++)
{
scanf("%d %d %d",&task,&a,&b);
if(task == 2)
{
if(searchfor(a) == searchfor(b))
printf("DA\n");
else
printf("NU/n");
}
else
{
int aux = searchfor(b);
father[aux]= searchfor(a);
}
}
}
int main()
{
freopen("disjoint.in","r",stdin);
freopen("disjoint.out","w",stdout);
Solve();
return 0;
}