#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 time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
3 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
4 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
5 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
6 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
7 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
8 |
Incorrect |
4 ms |
600 KB |
Output isn't correct |
9 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
10 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
11 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
12 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
13 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
14 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
15 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
16 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
17 |
Incorrect |
2 ms |
408 KB |
Output isn't correct |
18 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
19 |
Incorrect |
4 ms |
604 KB |
Output isn't correct |
20 |
Incorrect |
4 ms |
604 KB |
Output isn't correct |