Submission #222997

#TimeUsernameProblemLanguageResultExecution timeMemory
222997brcodetimeismoney (balkan11_timeismoney)C++14
45 / 100
19 ms1148 KiB
#include <iostream> #include <bits/stdc++.h> using namespace std; const long long MAXN = 210; vector<pair<pair<long long,long long>,pair<long long,long long>>> edges; vector<pair<int,int>> ans; long long par[MAXN]; long long sz[MAXN]; long long getpar(long long a){ if(par[a] == a){ return a; } return par[a] = getpar(par[a]); } void merge(long long a,long long b){ a = getpar(a); b = getpar(b); if(a==b){ return; } if(sz[a]>sz[b]){ swap(a,b); } par[a] = b; sz[b]+=sz[a]; } int main(){ long long n,m; cin>>n>>m; long long sum1 = 0; long long sum2 = 0; for(long long i=1;i<=m;i++){ long long x,y; cin>>x>>y; long long w1,w2; cin>>w1>>w2; edges.push_back(make_pair(make_pair(w1,w2),make_pair(x,y))); sum1+=w1; sum2+=w2; } for(long long i=0;i<=n;i++){ par[i] = i; sz[i] = 1; } long long res2 = 0; sort(edges.begin(),edges.end()); long long res = 0; for(auto e:edges){ long long x = e.second.first; long long y = e.second.second; long long w = e.first.first; long long w2 = e.first.second; if(getpar(x)!=getpar(y)){ merge(x,y); res+=w; res2+=w2; ans.push_back(make_pair(x,y)); } } cout<<res<<" "<<res2<<endl; for(auto x:ans){ cout<<x.first<<" "<<x.second<<endl; } }
#Verdict Execution timeMemoryGrader output
Fetching results...