Pagini recente » Cod sursa (job #1551397) | Arhiva de probleme | Cod sursa (job #1180295) | Cod sursa (job #938747) | Cod sursa (job #3162914)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("disjoint.in");
ofstream fout("disjoint.out");
int n, m, c, x, y, v[100001];
int root(int t){
if(v[t] == t) return t;
else{
v[t] = root(v[t]);
return v[t];
}
}
void join(int x, int y, int c){
int rx = root(x), ry = root(y);
if(rx == ry) return;
else{
if(rx < ry) v[ry] = rx;
else v[rx] = ry;
}
}
int main(){
fin>>n>>m;
for(int i=1; i<=n; i++) v[i] = i;
for(int i=1; i<=m; i++){
fin>>c>>x>>y;
if(c==1) join(x, y, c);
else fout<<(root(x)==root(y)?"DA":"NU")<<"\n";
}
return 0;
}