Submission #980007

#TimeUsernameProblemLanguageResultExecution timeMemory
980007HerreraDanielClosing Time (IOI23_closing)C++17
0 / 100
95 ms25928 KiB
#include "closing.h" #include <bits/stdc++.h> using namespace std; using ll = long long; using pll = pair<ll, ll>; ll countCities(vector<vector<pll>>& g, vector<ll>& c, ll X) { queue<pll> q; q.push({X, 0}); ll cnt = 0; vector<bool> v(g.size() + 1); while (q.size()) { ll curr = q.front().first, pC = q.front().second; q.pop(); if (pC > c[curr] || v[curr]) continue; v[curr] = true; cnt++; for (pll& nei : g[curr]) if (!v[nei.first]) q.push({nei.first, nei.second + pC}); } return cnt; } int max_score(int N, int X, int Y, long long K, std::vector<int> U, std::vector<int> V, std::vector<int> W) { ll sum = 0; vector<vector<pll>> g(N + 1); for (int i = 0; i < N; i++) { ll a = U[i], b = V[i], c = W[i]; g[a].push_back({b, c}); g[b].push_back({a, c}); } priority_queue<pair<ll, pll>, vector<pair<ll, pll>>, greater<pair<ll, pll>>> q; q.push({0, {X, X}}); q.push({0, {Y, Y}}); vector<ll> c(N, 0); vector<pair<bool, bool>> v(N); while (q.size()) { ll pC = q.top().first, curr = q.top().second.second, source = q.top().second.first; q.pop(); if (source == X && v[curr].first) continue; else if (source == X) v[curr].first = true; if (source == Y && v[curr].second) continue; else if (source == Y) v[curr].second = true; ll cost = pC - c[curr]; if (sum + cost > K) continue; sum += cost; c[curr] = pC; for (pll& nei : g[curr]) if ((source == X && v[nei.first].first) || (source == Y && v[nei.first].second)) continue; else q.push({nei.second + pC, {source, nei.first}}); } return countCities(g, c, X) + countCities(g, c, Y); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...