Pagini recente » Cod sursa (job #368796) | Cod sursa (job #417405) | Cod sursa (job #659904) | Cod sursa (job #3350428) | Cod sursa (job #3350422)
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ifstream fin("disjoint.in");
ofstream fout("disjoint.out");
#define N 100005
int n,m;
int root[N];
int find(int x){
if(root[x] != x) return find(root[x]);
else return x;
}
void unire(int x, int y){
root[find(y)] = find(x);
}
int main(){
fin >> n >> m;
for(int i = 1; i<=n; i++){
root[i] = i;
}
while(m--){
int c,x,y;
fin >> c >> x >> y;
if(c == 1) unire(x,y);
else{
if(find(x) == find(y)) fout << "DA\n";
else fout << "NU\n";
}
}
return 0;
}