# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
536964 | cig32 | timeismoney (balkan11_timeismoney) | C++17 | 15 ms | 1736 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "bits/stdc++.h"
using namespace std;
const int MAXN = 1e6 + 10;
const int MOD = 1e9 + 7;
#define int long long
mt19937_64 rng((int)std::chrono::steady_clock::now().time_since_epoch().count());
int rnd(int x, int y) {
int u = uniform_int_distribution<int>(x, y)(rng); return u;
}
struct edge {
int to, a, b;
};
void solve(int tc) {
int n, m;
cin >> n >> m;
vector<edge> adj[n];
map<pair<int, int>, bool> oh;
for(int i=0; i<m; i++) {
int x, y, a, b;
cin >> x >> y >> a >> b;
oh[{x, y}] = 1;
adj[x].push_back({y, a, b});
adj[y].push_back({x, a, b});
}
int A = 0, B = 0;
bool intree[n];
intree[0] = 1;
for(int i=1; i<n; i++) intree[i] = 0;
vector<pair<int, int> > edges;
for(int i=1; i<n; i++) {
int mi = 1e18, id, opt_a, opt_b, opt_fr;
for(int j=0; j<n; j++) {
if(intree[j]) {
for(int k=0; k<adj[j].size(); k++) {
if(intree[adj[j][k].to]) continue;
int cost = (A + adj[j][k].a) * (B + adj[j][k].b);
if(cost < mi) {
mi = cost;
id = adj[j][k].to;
opt_a = adj[j][k].a;
opt_b = adj[j][k].b;
opt_fr = j;
}
}
}
}
if(oh[{opt_fr, id}]) edges.push_back({opt_fr, id});
else edges.push_back({id, opt_fr});
intree[id] = 1;
A += opt_a;
B += opt_b;
}
cout << A << " " << B << "\n";
for(pair<int, int> x: edges) cout << x.first << ' ' << x.second << "\n";
}
int32_t main(){
ios::sync_with_stdio(0); cin.tie(0);
int t = 1; //cin >> t;
for(int i=1; i<=t; i++) solve(i);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |