Pagini recente » Cod sursa (job #1022176) | Cod sursa (job #2675734) | Cod sursa (job #2701811) | Cod sursa (job #185385) | Cod sursa (job #2884527)
#include <bits/stdc++.h>
#define ll long long
#define INF 0x3F3F3F3F
using namespace std;
const string fisier = "disjoint";
ifstream fin (fisier + ".in");
ofstream fout (fisier + ".out");
const int N_MAX = 1e5 + 5;
int n , m , t[N_MAX];
int root (int x){
int node = x;
while (x != t[x]){
x = t[x];
}
t[node] = x;
return x;
}
void disjoint (int x , int y){
int tx = root(x) , ty = root(y);
if (tx != ty){
t[tx] = ty;
}
}
int main(){
ios_base::sync_with_stdio(false);
fin >> n >> m;
for (int i=1; i<=n; i++){
t[i] = i;
}
for (int i=1; i<=m; i++){
int op , x , y; fin >> op >> x >> y;
if (op == 2){
fout << ((root(x) == root(y)) ? "DA" : "NU") << '\n';
}
if (op == 1){
disjoint(x , y);
}
}
}