Cod sursa(job #2501349)
| Utilizator | Data | 29 noiembrie 2019 16:00:35 | |
|---|---|---|---|
| Problema | Arbore partial de cost minim | Scor | 0 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.55 kb |
#include <iostream>
#include <fstream>
ifstream fin("disjoint.in");
ofstream fout("disjoint.out");
int tata[100001];
int find1(int x){
if(tata[x]==x)
return x
else
return tata[x]=find1(x);
}
void union1(int x,int y){
int sefx=find1(x),sefy=find1(y);
tata[sefy]=sefx;
}
using namespace std;
int main()
{
int n,m,i,x,y,op;
fin>>n>>m;
for(i=1;i<=m;i++){
fin>>op>>x>>y;
if(op==1)
union1(x,y);
else{
if(find1(x)==find1(y))
fout<<"DA"<<"\n";
else
fout<<"NU"<<"\n;
}
}
return 0;
}
