Cod sursa(job #2941930)

Utilizator redstonegamer22Andrei Ion redstonegamer22 Data 18 noiembrie 2022 15:58:22
Problema Arbore partial de cost minim Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.43 kb
#include <bits/stdc++.h>
#define t int
using namespace std;ifstream i("apm.in");ofstream o("apm.out");const t h=3e5;t p[h];vector<vector<t>>g[h+h],f;t a(t x){if(x^p[x])p[x]=a(p[x]);return p[x];}t n,m,x,y,c,s;main(){i>>n>>m;iota(p,p+h,0);while(m--){i>>x>>y>>c;g[c+h].push_back({x,y});}for(c=0;c<h+h;c++)for(auto e:g[c]){x=a(e[0]);y=a(e[1]);if(x^y)f.push_back(e),s+=c-h;p[x]=y;}o<<s<<'\n'<<n-1<<'\n';for(auto e:f)o<<e[0]<<" "<<e[1]<<'\n';}