Pagini recente » Cod sursa (job #661489) | Cod sursa (job #351364) | Cod sursa (job #2012468) | Cod sursa (job #578001) | Cod sursa (job #2015044)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("disjoint.in");
ofstream fout("disjoint.out");
int n,k,t[100002];
inline void Union(int x,int y)
{
t[y]=x;
}
int FindRoot(int x)
{
int rad,y;
for(rad=x;t[rad]!=0;rad=t[rad])
;
while(x!=rad)
{
y=t[x];
t[x]=rad;
x=y;
}
return rad;
}
int main()
{
int i,op,x,y;
fin>>n>>k;
for(i=1;i<=k;i++)
{
fin>>op>>x>>y;
x=FindRoot(x);
y=FindRoot(y);
if(op==1)
{
if(x!=y)Union(x,y);
}
else
{
if(x==y)fout<<"DA\n";
else fout<<"NU\n";
}
}
return 0;
}