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 "closing.h"
#include "bits/stdc++.h"
using namespace std;
using i32 = int;
#define int long long
#define len(x) (int)(x.size())
#define all(x) x.begin(), x.end()
template<typename T>
using vec = vector<T>;
i32 max_score(i32 N, i32 X, i32 Y, int K, std::vector<i32> U, std::vector<i32> V, std::vector<i32> W) {
i32 ans = 0;
priority_queue<pair<int, int>, vec<pair<int, int>>, greater<>> pq;
vec<vec<pair<int, int>>> g(N);
for (int i = 0; i < len(U); i++) {
g[U[i]].emplace_back(V[i], W[i]);
g[V[i]].emplace_back(U[i], W[i]);
}
pq.emplace(0, X);
pq.emplace(0, Y);
vec<bool> used(N, false);
while (!pq.empty()) {
auto [cost, cur] = pq.top();
pq.pop();
if (used[cur]) continue;
if (K < cost) break;
used[cur] = true;
K -= cost;
ans++;
for(auto [u,w] : g[cur]){
if(used[u]) continue;
pq.emplace(cost+w,u);
}
}
return ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |