Cod sursa(job #2941956)

Utilizator redstonegamer22Andrei Ion redstonegamer22 Data 18 noiembrie 2022 16:19:42
Problema Arbore partial de cost minim Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.42 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(auto&z:g)for(auto&e:z){x=a(e[0]);y=a(e[1]);if(x^y)f.push_back(e),s+=&z-g-h;p[x]=y;}o<<s<<'\n'<<n-1<<'\n';for(auto&e:f)o<<e[0]<<" "<<e[1]<<'\n';}