Submission #918648

#TimeUsernameProblemLanguageResultExecution timeMemory
918648noyancanturktimeismoney (balkan11_timeismoney)C++17
0 / 100
4 ms604 KiB
#ifndef Local #pragma GCC optimize("O3,unroll-loops") const int lim=1e5+100; #else const int lim=3e3+100; #endif #include "bits/stdc++.h" using namespace std; #define int int64_t #define pb push_back const int mod=1e9+7; using pii=pair<int,int>; struct edge{ signed x,y,c1,c2; inline edge(){} inline edge(int x,int y,int c1,int c2) :x(x),y(y),c1(c1),c2(c2){} }; inline void solve(){ int n,m; cin>>n>>m; edge v[m]; for(int i=0;i<m;i++){ cin>>v[i].x>>v[i].y>>v[i].c1>>v[i].c2; } bool vis[n]; for(int i=0;i<n;i++){ vis[i]=0; } vis[0]=1; int A=0,B=0; edge best,ans[n-1]; #define cost(a) (a.c1*B+a.c2*A+a.c1*a.c2) for(int i=0;i<n-1;i++){ bool didnt=1; for(int j=0;j<m;j++){ if((vis[v[j].x]^vis[v[j].y])&&(didnt||cost(v[i])<cost(best))){ v[i]=best; } } ans[i]=best; A+=v[i].c1; B+=v[i].c2; vis[v[i].x]=vis[v[i].y]=1; } cout<<A<<" "<<B<<"\n"; for(int i=0;i<n-1;i++){ cout<<ans[i].x<<" "<<ans[i].y<<"\n"; } } signed main(){ ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0); #ifdef Local freopen(".in","r",stdin); freopen(".out","w",stdout); #else #endif int t=1; //cin>>t; while (t--) { solve(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...