Submission #979936

#TimeUsernameProblemLanguageResultExecution timeMemory
979936alo_54Closing Time (IOI23_closing)C++17
0 / 100
111 ms25172 KiB
#include "closing.h" #include <bits/stdc++.h> using namespace std; int x, y, n; struct Arista { int v; long long w; }; struct Nodo { vector <Arista> ady; long long distX, distY; }; struct Estado { long long p; int idx; }; vector <Nodo> tree; void bfs(int root, int n) { queue <Estado> cola; vector <bool> vis (n, false); cola.push({0, root}); vis[root] = true; while (!cola.empty()) { Estado curr = cola.front(); cola.pop(); if (root == x) { tree[curr.idx].distX = curr.p; } if (root == y) { tree[curr.idx].distY = curr.p; } for (auto i : tree[curr.idx].ady) { if (!vis[i.v]) { vis[i.v] = true; cola.push({curr.p + i.w, i.v}); } } } } int max_score(int N, int X, int Y, long long K, std::vector<int> U, std::vector<int> V, std::vector<int> W) { x = X; y = Y; n = N; tree.resize(N); for (int i = 0; i < N-1; i++) { tree[U[i]].ady.push_back({V[i], W[i]}); tree[V[i]].ady.push_back({U[i], W[i]}); } bfs(X, N); bfs(Y, N); int resp = N; long long sum = 0; queue <long long> pq; for (auto i : tree) { pq.push(min(i.distX, i.distY)); sum += (long long)min(i.distX, i.distY); } while (sum > K) { if (pq.empty()) { break; } sum -= pq.front(); pq.pop(); resp--; } return resp; }
#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...