Pagini recente » Cod sursa (job #2051794) | Cod sursa (job #1339306) | Cod sursa (job #2238939) | Cod sursa (job #2583164) | Cod sursa (job #3307486)
#include <bits/stdc++.h>
#define pb push_back
//#define int long long
using namespace std;
const int N=1e5+5;
int p[N],sz[N];
int get(int x)
{
if(p[x]==x) return x;
return p[x]=get(p[x]);
}
void unite(int x, int y)
{
x=get(x);y=get(y);
if(x==y) return;
if(sz[x]>sz[y]) swap(x,y);
sz[y]+=sz[x];
p[x]=y;
}
signed main()
{
ifstream cin("disjoint.in");ofstream cout("disjoint.out");
int n,q;
cin>>n>>q;
for(int i=1;i<=n;++i) p[i]=i,sz[i]=1;
while(q--)
{
int op;cin>>op;
if(op==1)
{
int x,y;cin>>x>>y;
unite(x,y);
}
else
{
int x,y;cin>>x>>y;
x=get(x);y=get(y);
cout<<(x==y ? "DA":"NU")<<'\n';
}
}
}