Pagini recente » Cod sursa (job #277392) | Cod sursa (job #1310720) | Cod sursa (job #881850) | Cod sursa (job #146699) | Cod sursa (job #2845347)
#include<bits/stdc++.h>
using namespace std;
#define INIT ios_base :: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define mp make_pair
#define pb push_back
#define ft first
#define sc second
#define ll long long
#define pii pair<int, int>
#define count_bits __builtin_popcount
#define int ll
ifstream fin("disjoint.in"); ofstream fout("disjoint.out");
#define cin fin
#define cout fout
int n, m;
int rep[100010];
int sz[100010];
void initialize(){
for(int i=1; i<=n; i++){
rep[i]=i;
sz[i]=1;
}
}
int get_rep(int u){
if(u!=rep[u]){
rep[u]=get_rep(rep[u]);
}
else{
return u;
}
}
void unite(int u, int v){
if(sz[u]>sz[v]){
sz[u]+=sz[v];
rep[v]=u;
}
else{
sz[v]+=sz[u];
rep[u]=v;
}
}
int32_t main(){
INIT
cin>>n>>m;
initialize();
for(int i=1; i<=m; i++){
int tp;
cin>>tp;
if(tp==1){
int x, y;
cin>>x>>y;
unite(get_rep(x), get_rep(y));
}
if(tp==2){
int x, y;
cin>>x>>y;
if(get_rep(x)==get_rep(y)){
cout<<"DA\n";
}
else{
cout<<"NU\n";
}
}
}
return 0;
}