# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
879786 | phoenix0423 | timeismoney (balkan11_timeismoney) | C++17 | 448 ms | 1108 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;
typedef long long ll;
typedef pair<int, int> pll;
#define fastio ios::sync_with_stdio(false), cin.tie(0)
#pragma GCC optimize("Ofast")
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 0, n + 1)
#define pb push_back
#define pf push_front
#define eb emplace_back
#define f first
#define s second
#define lowbit(x) x&-x
#define ckmin(a, b) a = min(a, b)
#define ckmax(a, b) a = max(a, b)
#define int long long
const int INF = 1e9 + 7;
const int maxn = 300;
const int maxm = 1e4 + 5;
int n, m;
int par[maxn];
int root(int x){ return x == par[x] ? x : par[x] = root(par[x]);}
struct edge{
edge(){}
edge(int _x, int _y, int _t, int _c, int _w) : x(_x), y(_y), t(_t), c(_c), w(_w){}
int x, y;
int t, c;
int w;
bool operator < (const edge& other) const{
return w < other.w;
}
} e[maxm];
struct pt{
int x, y; // (T, C)
pt(){}
pt(int _x, int _y) : x(_x), y(_y){}
pt operator - (const pt b){
return pt(x - b.x, y - b.y);
}
int cross(const pt b){
return x * b.y - y * b.x;
}
} ans, A, B;
vector<pll> best;
pt kruskal(){
for(int i = 0; i < n; i++) par[i] = i;
sort(e, e + m);
pt ret = {0, 0};
vector<pll> cur;
for(int i = 0; i < m; i++){
int x = root(e[i].x), y = root(e[i].y);
if(x == y) continue;
cur.eb(e[i].x, e[i].y);
par[x] = y, ret.x += e[i].t, ret.y += e[i].c;
}
if(ret.x * ret.y < ans.x * ans.y) ans = ret, best = cur;
return ret;
}
void work(pt A, pt B){ // divide and conquer
for(int i = 0; i < m; i++) e[i].w = e[i].t * (A.y - B.y) + e[i].c * (B.x - A.x);
pt C = kruskal();
if((B - A).cross(C - A) >= 0) return;
work(A, C), work(C, B);
}
signed main(void){
fastio;
cin>>n>>m;
ans = {INF, 1};
for(int i = 0; i < m; i++){
int x, y, t, c;
cin>>x>>y>>t>>c;
e[i] = edge(x, y, t, c, 0);
}
for(int i = 0; i < m; i++) e[i].w = e[i].t;
A = kruskal();
for(int i = 0; i < m; i++) e[i].w = e[i].c;
B = kruskal();
work(A, B);
cout<<ans.x<<" "<<ans.y<<"\n";
for(auto [x, y] : best) cout<<x<<" "<<y<<"\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |