Cod sursa(job #3252483)
| Utilizator | Data | 29 octombrie 2024 19:06:36 | |
|---|---|---|---|
| Problema | Paduri de multimi disjuncte | Scor | 0 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.6 kb |
#include<fstream>
#include<cmath>
using namespace std;
ifstream fin("disjoint.in");
ofstream fout("disjoint.out");
const int nmax = 100000;
int n,m,tata[nmax];
int find(int nod){
if(tata[nod] == 0)return nod;
else find(tata[nod]);
}
int main(){
fin>>n>>m;
for(int i = 1; i <= m; i++){
int x,y,z;
fin>>z>>x>>y;
if(z == 1){
int a = min(x,y), b = max(x,y);
tata[b] = a;
}
else{
int tx = find(x), ty = find(y);
if(tx == ty)fout<<"DA\n";
else fout<<"NU\n";
}
}
}
