Pagini recente » Cod sursa (job #425371) | Cod sursa (job #903402) | Cod sursa (job #916945) | Cod sursa (job #2369446) | Cod sursa (job #3352606)
/*
* author [dubit]
*/
#include <bits/stdc++.h>
using namespace std;
int root[100005];
int findroot(int x)
{
if(root[x]==x)
return x;
return root[x]=findroot(root[x]);
}
void dsu(int a,int b)
{
int ra=findroot(a),rb=findroot(b);
if(ra!=rb)
root[ra]=rb;
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
freopen("disjoint.in","r",stdin);
freopen("disjoint.out","w",stdout);
int n,m,cod,x,y;
cin>>n>>m;
for(int i=1;i<=n;i++)
root[i]=i;
while(m--)
{
cin>>cod>>x>>y;
if(cod==1)
dsu(x,y);
else
cout<<((findroot(x)==findroot(y)) ? "DA\n" : "NU\n");
}
return 0;
}