Pagini recente » Cod sursa (job #36624) | Cod sursa (job #1177388) | Cod sursa (job #2256838) | Cod sursa (job #2384968) | Cod sursa (job #2144212)
#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",&a,&b,&task);
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;
}