Submission #1142207

#TimeUsernameProblemLanguageResultExecution timeMemory
1142207AliMark71timeismoney (balkan11_timeismoney)C++20
45 / 100
2095 ms131072 KiB
// // main.cpp // IntensiveCamp 1 2025 // // Created by Ali AlSalman on 24/01/2025. // #include <bits/stdc++.h> template<typename T> using vec = std::vector<T>; using namespace std; typedef vec<pair<int, int>> mst_t; typedef pair<int, int> cost_time_t; typedef pair<mst_t, cost_time_t> mst_res_t; vec<function<bool(array<int, 4>, array<int, 4>)>> call_backs; vec<bool> vs; vec<vec<array<int, 3>>> adj; mst_res_t mst(int piv, int a = -1, int b = -1) { mst_t tree; fill(vs.begin(), vs.end(), 0); long long sum_c = 0, sum_t = 0; auto cmp_maker = [](int i, int a = -1, int b = -1) -> function<bool(array<int, 4>, array<int, 4>)>{ if (i == 1 || i == 2) { return [i](array<int, 4> lhs, array<int, 4> rhs) -> bool { return lhs[i + 1] > rhs[i + 1]; }; } else { return [a, b](array<int, 4> lhs, array<int, 4> rhs) -> bool { return a * lhs[2] + b * lhs[3] > a * rhs[2] + b * rhs[3]; }; } }; priority_queue< array<int, 4>, vec<array<int, 4>>, decltype(cmp_maker(piv, a, b)) > q(cmp_maker(piv, a, b)); q.push({0, -1, 0, 0}); while (!q.empty()) { auto [u, v, _c, _t] = q.top(); q.pop(); if (vs[u]) continue; vs[u] = 1; if (0 <= u && 0 <= v) tree.push_back({u, v}); sum_c += _c; sum_t += _t; for (auto [c, c_c, c_t] : adj[u]) if (!vs[c]) { q.push({c, u, c_c, c_t}); } } return {tree, {sum_c, sum_t}}; } mst_res_t cnvx(mst_res_t a, mst_res_t b) { auto min_p = [](mst_res_t a, mst_res_t b) { if (a.second.first * a.second.second <= b.second.first * b.second.second) return a; return b; }; auto p = mst(3, a.second.second - a.second.first, b.second.first - b.second.second); if (p == a || p == b) return min_p(a, b); return min_p(cnvx(a, p), cnvx(p, b)); } void solve() { int n, m; cin>>n>>m; vs.resize(n); adj.resize(n); while (m--) { int a, b, c, d; cin>>a>>b>>c>>d; adj[a].push_back({b, c, d}); adj[b].push_back({a, c, d}); } auto c_point = mst(1); auto t_point = mst(2); auto opt_point = cnvx(c_point, t_point); cout<<opt_point.second.first<<" "<<opt_point.second.second<<endl; for (auto [u, v] : opt_point.first) cout<<u<<" "<<v<<endl; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int t = 1; // cin>>t; while (t--) solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...