Pagini recente » Cod sursa (job #2595138) | Cod sursa (job #2629915) | Cod sursa (job #1146851) | Cod sursa (job #1853936) | Cod sursa (job #2094382)
#include <bits/stdc++.h>
#define NMAX 100010
using namespace std;
ofstream fout("disjoint.out");
ifstream fin("disjoint.in");
int m, n, p[NMAX], o, x, y;
int findroot(int x){
if(p[x] == 0){
return x;
}
p[x] = findroot(p[x]);
return p[x];
}
void op1(int x, int y){
x = findroot(x);
y = findroot(y);
p[x] = y;
}
string op2(int x, int y){
x = findroot(x);
y = findroot(y);
if(x == y){
return "DA\n";
}
else return "NU\n";
}
int main(){
fin >> n >> m;
for(int i = 1; i <= m; i++){
fin >> o >> x >> y;
if(o == 1){
op1(x, y);
}
else{
fout << op2(x, y);
}
}
}