Pagini recente » Cod sursa (job #752732) | Cod sursa (job #273879) | Istoria paginii runda/sim04/clasament | Cod sursa (job #1766568) | Cod sursa (job #296720)
Cod sursa(job #296720)
#include <stdio.h>
#define nmax 100005
#define mmax 100005
int n, m, t [nmax];
void init ()
{
int i;
for (i=1; i <= n; ++i)
t [i]=i;
}
int grup (int nod)
{
if (t [nod] == nod)
return nod;
return t [nod]=grup (t [nod]);
}
inline void uneste (int a, int b)
{
t [grup (a)]=grup (b);
}
int main ()
{
freopen ("disjoint.in", "r", stdin);
freopen ("disjoint.out", "w", stdout);
int i, tip, a, b;
scanf ("%d%d", &n, &m);
init ();
for (i=1; i <= m; ++i)
{
scanf ("%d%d%d", &tip, &a, &b);
if (tip == 1)
uneste (a, b);
else
if (grup (a) == grup (b))
printf ("DA\n");
else
printf ("NU\n");
}
return 0;
}