Pagini recente » Cod sursa (job #3266478) | Cod sursa (job #1158903) | Cod sursa (job #79012) | Cod sursa (job #1795755) | Cod sursa (job #2525954)
#include <bits/stdc++.h>
#define pb push_back
using namespace std;
ifstream fin("disjoint.in");
ofstream fout("disjoint.out");
void debug_out() { cerr << '\n'; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...);}
#define dbg(...) cerr << #__VA_ARGS__ << " ->", debug_out(__VA_ARGS__)
#define dbg_v(x, n) do{cerr<<#x"[]: ";for(int _=0;_<n;++_)cerr<<x[_]<<" ";cerr<<'\n';}while(0)
#define dbg_ok cerr<<"OK!\n"
typedef pair<int,int> pii;
typedef long long int ll;
typedef long double ld;
const int DMAX = 1e5+10;
int tata[DMAX];
int n,m;
void unire(int x,int y);
int comp(int x);
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int t,i,op,x,y;
fin>>n>>m;
for(i=1;i<=m;i++){
fin>>op>>x>>y;
if(op & 1){
if(comp(x) != comp(y))
unire(x,y);
}
else{
if(comp(x) == comp(y))
fout<<"DA\n";
else
fout<<"NU\n";
}
}
return 0;
}
int comp(int x){
int root = x;
while(tata[root])
root = tata[root];
int aux;
while (tata[x]) {
aux = tata[x];
tata[x] = root;
x = aux;
}
return root;
}
void unire(int x,int y){
x=comp(x);
y=comp(y);
tata[x]=y;
}