Pagini recente » Cod sursa (job #1606979) | Cod sursa (job #321930) | Cod sursa (job #221295) | Cod sursa (job #247639) | Cod sursa (job #526091)
Cod sursa(job #526091)
#include <algorithm>
using namespace std;
#define DIM 100005
int t[DIM],r[DIM];
int n,m;
inline int find (int x)
{
if (x!=t[x])
t[x]=find (t[x]);
return t[x];
}
inline void unite (int x,int y)
{
if (r[x]<r[y])
t[x]=y;
else
t[y]=x;
if (r[x]==r[y])
++r[x];
}
void solve ()
{
int i,tip,a,b;
for (i=1; i<=n; ++i)
t[i]=i;
for (i=1; i<=m; ++i)
{
scanf ("%d%d%d",&tip,&a,&b);
if (tip==1)
unite (find (a),find (b));
else
if (find (a)==find (b))
printf ("DA\n");
else
printf ("NU\n");
}
}
int main ()
{
freopen ("disjoint.in","r",stdin);
freopen ("disjoint.out","w",stdout);
scanf ("%d%d",&n,&m);
solve ();
return 0;
}