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 <bits/stdc++.h>
#include "closing.h"
using namespace std;
using ll = long long;
int N, X, Y;
ll maxCost;
vector<vector<pair<int, ll>>> g;
int solveGreedy(){
priority_queue<tuple<ll, int, int>> pq;
pq.emplace(0, X, X);
pq.emplace(0, Y, Y);
ll remain = maxCost;
int score = 0;
while(remain >= 0 && !pq.empty()){
auto [c, u, p] = pq.top(); pq.pop();
if(remain + c < 0) break;
remain += c;
score++;
for(auto [v, w] : g[u]){
if(v != p) pq.emplace(c-w, v, u);
}
}
return score;
}
int max_score(int N_, int X_, int Y_, ll K, vector<int> U, vector<int> V, vector<int> W){
N = N_, X = X_, Y = Y_, maxCost = K;
g.clear();
g.resize(N);
for(int i = 0; i < N-1; i++){
g[U[i]].emplace_back(V[i], W[i]);
g[V[i]].emplace_back(U[i], W[i]);
}
return solveGreedy();
}
# | 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... |