Cod sursa(job #2941966)

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