Submission #43719

#TimeUsernameProblemLanguageResultExecution timeMemory
43719ssnsarang2023timeismoney (balkan11_timeismoney)C++14
100 / 100
708 ms1692 KiB
#include <cstdio> #include <iostream> #include <algorithm> #include <functional> #include <vector> #include <cstring> #include <cmath> #include <queue> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> ii; #define SZ(x) ((int)x.size()) //#define debug struct edge { int u, v, t, c; edge(int _u, int _v, int _t, int _c) : u(_u), v(_v), t(_t), c(_c) {} }; const int N = (int)205; int n, m, f[N], mnt = 1e9, mnc = 1e9; ii opt = ii(1e9, 1e9); vector<edge> e; int getf(int x) { return f[x] = f[x] == x ? x : getf(f[x]); } bool mergef(int x, int y) { int u = getf(x), v = getf(y); if (u == v) return false; f[v] = u; return true; } ii get_mst(int ta, int ca, int mode) { //mode = 1 <=> output answer for (int i = 0; i < n; ++i) f[i] = i; sort(e.begin(), e.end(), [&] (const edge &x, const edge &y) { return 1ll * x.t * ta + 1ll * x.c * ca < 1ll * y.t * ta + 1ll * y.c * ca; }); int sumt = 0, sumc = 0; for (int i = 0; i < m; ++i) { if (mergef(e[i].u, e[i].v)) { sumt += e[i].t; sumc += e[i].c; if (mode) printf("%d %d\n", e[i].u, e[i].v); } } if (1ll * sumt * sumc < 1ll * mnt * mnc) { mnt = sumt; mnc = sumc; opt = ii(ta, ca); } return ii(sumt, sumc); } bool ccw(const ii &a, const ii &b, const ii &c){ int dx1 = b.first - a.first; int dy1 = b.second - a.second; int dx2 = c.first - a.first; int dy2 = c.second - a.second; return 1ll * dx1 * dy2 >= 1ll * dy1 * dx2; } void solve(const ii &s, const ii &t) { ii mid = get_mst(s.second - t.second, t.first - s.first, 0); if (!ccw(t, mid, s)) { solve(s, mid); solve(mid, t); } } int main() { #ifdef debug freopen("inp.txt", "rt", stdin); #endif scanf("%d%d", &n, &m); for (int i = 1; i <= m; ++i) { int u, v, t, c; scanf("%d%d%d%d", &u, &v, &t, &c); e.push_back(edge(u, v, t, c)); } ii s = get_mst(1, 0, 0); //minimize t ii t = get_mst(0, 1, 0); //minimize c solve(s, t); printf("%d %d\n", mnt, mnc); get_mst(opt.first, opt.second, 1); return 0; }

Compilation message (stderr)

timeismoney.cpp: In function 'int main()':
timeismoney.cpp:79:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &n, &m);
                       ^
timeismoney.cpp:82:36: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d%d%d", &u, &v, &t, &c);
                                    ^
#Verdict Execution timeMemoryGrader output
Fetching results...