Pagini recente » Cod sursa (job #2568240) | Cod sursa (job #1460591) | Cod sursa (job #1747020) | Cod sursa (job #2066859) | Cod sursa (job #2144221)
#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;
}