Cod sursa(job #2943290)

Utilizator lucaperjuLuca Perju Verzotti lucaperju Data 20 noiembrie 2022 20:00:48
Problema Arbore partial de cost minim Scor 10
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.38 kb
#import<bits/stdc++.h>
std::ifstream r("apm.in");std::ofstream w("apm.out");struct s{int x,y,z;}d,e['■'];int m,k,i,z,t['■'],x;int f(int x){return t[x]?t[x]=f(t[x]):x;}int main(){r>>m>>m;while(r>>e[i].x>>e[i].y>>e[i].z)i++;std::sort(e,e+m,[](s a,s b){return a.z>b.z;});for(;i;)d=e[--i],(x=f(d.x))^f(d.y)?t[x]=d.y,z+=d.z,e[k++]=d:d;w<<z<<" "<<k<<" ";while(k--)w<<e[k].x<<" "<<e[k].y<<" ";}