제출 #1128947

#제출 시각아이디문제언어결과실행 시간메모리
1128947jamkeltimeismoney (balkan11_timeismoney)C++20
0 / 100
1 ms584 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define nd second #define st first struct edge { ll u; ll v; ll a; ll b; }; ll va,vb; ll n,m; bool por(edge &a, edge&b) { return a.a*va+a.b*vb<b.a*va+b.b*vb; } ll f(vector<ll>&u,ll i) { if(u[i]==i)return i; return u[i]=f(u,u[i]); } pair<ll,ll>mst(vector<edge>&a) { sort(a.begin(),a.end(),por); vector<ll>u(n); for(int i=0;i<n;i++)u[i]=i; pair<ll,ll>w; for(int i=0;i<m;i++) { if(f(u,a[i].u)!=f(u,a[i].v)) { w.st+=a[i].a; w.nd+=a[i].b; u[u[a[i].u]]=u[a[i].v]; } } return w; } int main() { ios_base::sync_with_stdio(0);cin.tie(0); cin>>n>>m; vector<edge>a(m); for(int i=0 ;i<n; i++) { cin>>a[i].u>>a[i].v>>a[i].a>>a[i].b; } va=1;vb=1; cout<<pow(mst(a).st,2)<<endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...