Cod sursa(job #2615878)
| Utilizator | Data | 15 mai 2020 18:57:27 | |
|---|---|---|---|
| Problema | Paduri de multimi disjuncte | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.65 kb |
#include <fstream>
using namespace std;
ifstream f("disjoint.in");
ofstream g("disjoint.out");
int t[100005],n,m;
int Find(int x){
int r=x,r1;
while(t[r]){
r=t[r];
}
while(t[x]){
r1=t[x];
t[x]=r;
x=r1;
}
return r;
}
void Union(int x,int y){
t[y]=x;
}
void rez(){
f>>n>>m;
int i,c,x,y;
for(i=1;i<=m;i++){
f>>c>>x>>y;
x=Find(x);
y=Find(y);
if(c==1){
Union(x,y);
}else{
if(x==y){
g<<"DA \n";
}else{
g<<"NU \n";
}
}
}
}
int main()
{
rez();
return 0;
}
