// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("unroll-loops")
#include "closing.h"
#include <queue>
#include <vector>
using namespace std;
#define ff first
#define ss second
#define mp make_pair
vector<vector<pair<int,long long>>>v;
vector<bool>vis1,vis2;
vector<long long>c;
int max_score(int N, int X, int Y, long long K,
vector<int> U, vector<int> V, vector<int> W){
v.assign(N,vector<pair<int,long long>>(0));
vis1.assign(N,false);
vis2.assign(N,false);
for(int i=0;i<N-1;i++){
v[U[i]].push_back({V[i],W[i]});
v[V[i]].push_back({U[i],W[i]});
}
c.assign(N,0);
priority_queue<pair<pair<long long,long long>,pair<int,int>>>q;
vis1[X]=true;
vis2[Y]=true;
for(auto [z,w]:v[X]) q.push({{-w,-w},{z,1}});
for(auto [z,w]:v[Y]) q.push({{-w,-w},{z,2}});
while(!q.empty()){
auto [d,y]=q.top();
int x=y.ff,id=y.ss;
q.pop();
if(K+d.ff<0){
break;
}
c[x]=max(c[x],-d.ss);
K+=d.ff;
if(id==1) vis1[x]=true;
else vis2[x]=true;
for(auto [z,w]:v[x]){
if(id==1 && !vis1[z]){
q.push(mp(mp(min(0LL,d.ss+c[z]),d.ss-w),mp(z,id)));
}
if(id==2 && !vis2[z]){
q.push(mp(mp(min(0LL,d.ss+c[z]),d.ss-w),mp(z,id)));
}
}
}
int ans=0;
for(int i=0;i<N;i++){
ans+=vis1[i];
ans+=vis2[i];
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
69 ms |
21588 KB |
1st lines differ - on the 1st token, expected: '451', found: '453' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
1st lines differ - on the 1st token, expected: '30', found: '31' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
1st lines differ - on the 1st token, expected: '30', found: '31' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
1st lines differ - on the 1st token, expected: '30', found: '31' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Incorrect |
0 ms |
348 KB |
1st lines differ - on the 1st token, expected: '30', found: '31' |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Incorrect |
0 ms |
348 KB |
1st lines differ - on the 1st token, expected: '30', found: '31' |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Incorrect |
0 ms |
348 KB |
1st lines differ - on the 1st token, expected: '30', found: '31' |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Incorrect |
0 ms |
348 KB |
1st lines differ - on the 1st token, expected: '30', found: '31' |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Incorrect |
0 ms |
348 KB |
1st lines differ - on the 1st token, expected: '30', found: '31' |
4 |
Halted |
0 ms |
0 KB |
- |