Cod sursa(job #2304086)

Utilizator Bogdan_BuzatuBuzatu Bogdan Mihai Bogdan_Buzatu Data 17 decembrie 2018 15:02:43
Problema Arbore partial de cost minim Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.21 kb
#include <fstream>
#include <iostream>
#include <algorithm>
using namespace std;
ifstream fin("disjoint.in");
ofstream fout("disjoint.out");
int t[100100],x,y,n,p,op,rx,ry,s,k;
pair<int, pair<int,int> > pereche[400010];
pair<int,int> sol[400100];
int rad(int xx){
    while(t[xx]>0){
        xx=t[xx];
    }
    return xx;
}
int main(){
    fin>>n>>p;
    for(int i=1;i<=n;i++){
        t[i]=-1;
    }

    for(int i=1;i<=p;i++){
        fin>>pereche[i].first>>pereche[i].second.first>>pereche[i].second.second;
        fout<<pereche[i].first<<" "<<pereche[i].second.first<<" "<<pereche[i].second.second<<"\n";
    }
    sort(pereche+1,pereche+p+1);

   for(int i=1;i<=p;i++){

        rx=rad(pereche[i].second.first);
        ry=rad(pereche[i].second.second);
        /*if(rx!=ry){
            s+=pereche[i].first;
            k++;
            sol[k].first=pereche[i].second.first;
            sol[k].second=pereche[i].second.second;

            if(t[rx]<t[ry]){
                t[rx]+=t[ry];
                t[ry]=rx;

            }
            else{
                t[ry]+=t[rx];
                t[rx]=ry;
            }
        }
         */

    }





    fout<<s;


}