Pagini recente » Cod sursa (job #2380467) | Cod sursa (job #1048993) | Cod sursa (job #848915) | Cod sursa (job #1023294) | Cod sursa (job #2675153)
#include <bits/stdc++.h>
using namespace std;
ifstream in("disjoint.in");
ofstream out("disjoint.out");
int n,q,t,x,y,p[100001],v[100001];
int main()
{ in>>n>>q;
while(q--)
{ in>>t>>x>>y;
if(t==1)
{ while(p[x]!=0)
x=p[x];
while(p[y]!=0)
y=p[y];
if(v[x]<v[y])
swap(x,y);
p[y]=x;
v[x]+=v[y]+1;
}
else
{ while(p[x]!=0)
x=p[x];
while(p[y]!=0)
y=p[y];
if(x==y)
out<<"DA\n";
else
out<<"NU\n";
}
}
in.close();
out.close();
return 0;
}