Cod sursa(job #883079)
#include <fstream>
using namespace std;
ifstream fin("disjoint.in");
ofstream fout("disjoint.out");
long n;
long h[100000];
long t[100000];
long u;
inline int drum (int nod)
{
while(t[nod])
nod=t[nod];
return nod;
}
void paduri(int c, int x,int y)
{
if(c==1)
{
if(drum(x)!=drum(y))
{
if(h[x]==h[y])
{
t[x]=y;
h[y]++;
}
else
if(h[x]<h[y])
t[x]=y;
else
t[y]=x;
}
}
else
if(drum(x)==drum(y))
fout<<"DA"<<'\n';
else
fout<<"NU"<<'\n';
}
void cit()
{
fin>>n>>u;
}
int main()
{
int i;
cit();
int c,x,y;
// fout<<n<<" "<<u<<'\n';
for(i=1;i<=u;i++)
{
fin>>c>>x>>y;
paduri(c,x,y);
//fout<<c<<" "<<x<<" "<<y<<'\n';
}
// fout<<'\n';
return 0;
}