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 <vector>
#include <bits/stdc++.h>
using namespace std;
int n , x , y;
long long k;
const int N = 200010;
vector< pair< int , int > > g[N];
long long a[N] , b[N];
void DFS(int node,int prnt,long long *a,long long dist){
a[node] = dist;
for(int i = 0 ;i < (int)g[node].size();i++){
if(g[node][i].first != prnt)
DFS(g[node][i].first , node , a , dist + g[node][i].second);
}
}
int max_score(int N, int X, int Y, long long K,std::vector<int> U, std::vector<int> V, std::vector<int> W)
{
for(int i = 0;i < n;i++) g[i].clear();
n = N, x = X , y = Y , k = K;
for(int i = 0 ;i < (int)U.size();i++){
g[U[i]].push_back(make_pair(V[i] , W[i]));
g[V[i]].push_back(make_pair(U[i] , W[i]));
}
DFS(X , -1 , a , 0);
DFS(Y, - 1, b , 0);
priority_queue < long long > q;
for(int i = 0 ;i < n;i++){
q.push(-min(a[i] , b[i]));
}
int ans = 0;
while(!q.empty()){
k += q.top();
q.pop();
if(k < 0) break;
ans++;
}
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... |