Pagini recente » Cod sursa (job #1917401) | Cod sursa (job #1923075)
# include <bits/stdc++.h>
# define maxn 500001
# define ll long long
# define clock (clock() * 1000.0 / CLOCKS_PER_SEC)
# define rc(s) return cout << s,0
# define _ ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
# define pb push_back
# define mp make_pair
//# define int ll
using namespace std;
const int inf = INT_MAX;
int n,m,x,y,z,p[100001];
int f(int nod)
{
if(p[nod] == nod) return nod;
return f(p[nod]);
}
int unite(int x,int y)
{
p[f(x)] = f(y);
}
int32_t main(){_
freopen("disjoint.in","r",stdin);
freopen("disjoint.out","w",stdout);
cin >> n >> m;
for(int i = 1;i<=n;i++) p[i] = i;
while(m--)
{
cin >> x >> y >> z;
if(x == 1)
unite(y,z);
else cout << (f(y) == f(z) ? "DA" : "NU") << '\n';
}
return 0;
}