Pagini recente » Cod sursa (job #2123808) | Cod sursa (job #2933148) | Cod sursa (job #2335944) | Cod sursa (job #2893076) | Cod sursa (job #353214)
Cod sursa(job #353214)
#include<stdio.h>
#define nmax 100005
long n,m;
long v[nmax];
struct nod
{
long info;
nod *urm;
};
nod *t[nmax];
void read()
{
scanf("%ld%ld",&n,&m);
}
void init()
{
long i;
nod *aux;
for (i=1;i<=n;i++)
{
aux=new nod;
aux->info=i;
aux->urm=NULL;
t[i]=aux;
v[i]=i;
}
}
void connect(long a,long b)
{
nod *p,*aux;
long r,s;
r=v[a];
s=v[b];
p=t[s];
while (p)
{
aux=p;
t[s]=p->urm;
p=t[s];
v[aux->info]=r;
aux->urm=t[r];
t[r]=aux;
}
}
void rez()
{
long i,a,b,c;
for (i=1;i<=m;i++)
{
scanf("%ld%ld%ld",&c,&a,&b);
if (c==1)
if (v[a]<v[b])
connect(a,b);
else connect(b,a);
else
if (v[a]==v[b])
printf("DA\n");
else printf("NU\n");
}
}
int main()
{
freopen("disjoint.in","r",stdin);
freopen("disjoint.out","w",stdout);
read();
init();
rez();
return 0;
}