#include "closing.h"
#include<bits/stdc++.h>
using namespace std;
vector<pair<int,int>>adj[200100];
vector<long long>v;
void dfs(int n,int p,long long d){
v.push_back(d);
for(auto[i,w]:adj[n])
if(i-p)dfs(i,n,d+w);
}
int max_score(int N, int X, int Y, long long K,std::vector<int> U, std::vector<int> V, std::vector<int> W){
vector<long long>pos(N);
for(int i=1;i<N;i++)
pos[i]=pos[i-1]+W[i-1];
for(int i=0;i<N-1;i++)
adj[U[i]].push_back({V[i],W[i]}),
adj[V[i]].push_back({U[i],W[i]});
v.clear();
dfs(X,N,0);
dfs(Y,N,0);
sort(v.rbegin(),v.rend());
long long origK=K;
while(v.size())
if(v.back()<=K)
K-=v.back(),
v.pop_back();
else break;
for(int i=0;i<N;i++)
adj[i].clear();
K=origK;
int ans1=2*N-v.size();
priority_queue<pair<int,int>,vector<pair<int,int>>,greater<>> pq;
int ans2=0;
for(int i=X;i<Y;i++){
int A=pos[i]-pos[X];
int B=pos[Y]-pos[i];
K-=min(A,B);ans2++;
pq.push({max(B,A)-min(A,B),1});
}
for(int i=0;i<X;i++)
pq.push({pos[X]-pos[i],0});
for(int i=Y;i<N;i++)
pq.push({pos[i]-pos[Y],0});
if(K<0)
ans2=0;
while(pq.size()){ auto[a,b]=pq.top();
if(a>K)break;K-=a;pq.pop();ans2++;
if(!b)pq.push({pos[Y]-pos[X],1});
}
return max(ans1,ans2);
}
Compilation message
closing.cpp: In function 'int max_score(int, int, int, long long int, std::vector<int>, std::vector<int>, std::vector<int>)':
closing.cpp:47:9: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
47 | if(a>K)break;K-=a;pq.pop();ans2++;
| ^~
closing.cpp:47:22: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
47 | if(a>K)break;K-=a;pq.pop();ans2++;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
4952 KB |
1st lines differ - on the 1st token, expected: '6', found: '5' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
109 ms |
33208 KB |
1st lines differ - on the 1st token, expected: '451', found: '252360' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4956 KB |
Output is correct |
2 |
Correct |
1 ms |
4956 KB |
Output is correct |
3 |
Correct |
1 ms |
4956 KB |
Output is correct |
4 |
Correct |
1 ms |
4956 KB |
Output is correct |
5 |
Correct |
1 ms |
4956 KB |
Output is correct |
6 |
Correct |
1 ms |
4956 KB |
Output is correct |
7 |
Correct |
1 ms |
4956 KB |
Output is correct |
8 |
Correct |
1 ms |
4956 KB |
Output is correct |
9 |
Correct |
1 ms |
4956 KB |
Output is correct |
10 |
Correct |
1 ms |
4956 KB |
Output is correct |
11 |
Correct |
1 ms |
4952 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4956 KB |
Output is correct |
2 |
Correct |
1 ms |
4956 KB |
Output is correct |
3 |
Correct |
1 ms |
4956 KB |
Output is correct |
4 |
Correct |
1 ms |
4956 KB |
Output is correct |
5 |
Correct |
1 ms |
4956 KB |
Output is correct |
6 |
Correct |
1 ms |
4956 KB |
Output is correct |
7 |
Correct |
1 ms |
4956 KB |
Output is correct |
8 |
Correct |
1 ms |
4956 KB |
Output is correct |
9 |
Correct |
1 ms |
4956 KB |
Output is correct |
10 |
Correct |
1 ms |
4956 KB |
Output is correct |
11 |
Correct |
1 ms |
4952 KB |
Output is correct |
12 |
Correct |
1 ms |
4956 KB |
Output is correct |
13 |
Correct |
1 ms |
5136 KB |
Output is correct |
14 |
Correct |
1 ms |
4956 KB |
Output is correct |
15 |
Correct |
1 ms |
4956 KB |
Output is correct |
16 |
Correct |
2 ms |
4956 KB |
Output is correct |
17 |
Correct |
2 ms |
4956 KB |
Output is correct |
18 |
Correct |
2 ms |
4956 KB |
Output is correct |
19 |
Correct |
1 ms |
4956 KB |
Output is correct |
20 |
Correct |
1 ms |
5212 KB |
Output is correct |
21 |
Correct |
1 ms |
4956 KB |
Output is correct |
22 |
Correct |
1 ms |
5212 KB |
Output is correct |
23 |
Correct |
1 ms |
5212 KB |
Output is correct |
24 |
Correct |
1 ms |
5144 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4956 KB |
Output is correct |
2 |
Correct |
1 ms |
4956 KB |
Output is correct |
3 |
Correct |
1 ms |
4956 KB |
Output is correct |
4 |
Correct |
1 ms |
4956 KB |
Output is correct |
5 |
Correct |
1 ms |
4956 KB |
Output is correct |
6 |
Correct |
1 ms |
4956 KB |
Output is correct |
7 |
Correct |
1 ms |
4956 KB |
Output is correct |
8 |
Correct |
1 ms |
4956 KB |
Output is correct |
9 |
Correct |
1 ms |
4956 KB |
Output is correct |
10 |
Correct |
1 ms |
4956 KB |
Output is correct |
11 |
Correct |
1 ms |
4952 KB |
Output is correct |
12 |
Correct |
1 ms |
4956 KB |
Output is correct |
13 |
Correct |
1 ms |
5136 KB |
Output is correct |
14 |
Correct |
1 ms |
4956 KB |
Output is correct |
15 |
Correct |
1 ms |
4956 KB |
Output is correct |
16 |
Correct |
2 ms |
4956 KB |
Output is correct |
17 |
Correct |
2 ms |
4956 KB |
Output is correct |
18 |
Correct |
2 ms |
4956 KB |
Output is correct |
19 |
Correct |
1 ms |
4956 KB |
Output is correct |
20 |
Correct |
1 ms |
5212 KB |
Output is correct |
21 |
Correct |
1 ms |
4956 KB |
Output is correct |
22 |
Correct |
1 ms |
5212 KB |
Output is correct |
23 |
Correct |
1 ms |
5212 KB |
Output is correct |
24 |
Correct |
1 ms |
5144 KB |
Output is correct |
25 |
Correct |
2 ms |
5208 KB |
Output is correct |
26 |
Correct |
2 ms |
5468 KB |
Output is correct |
27 |
Correct |
2 ms |
5464 KB |
Output is correct |
28 |
Correct |
2 ms |
5480 KB |
Output is correct |
29 |
Correct |
3 ms |
5468 KB |
Output is correct |
30 |
Correct |
2 ms |
5468 KB |
Output is correct |
31 |
Correct |
2 ms |
5468 KB |
Output is correct |
32 |
Correct |
2 ms |
5476 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
4952 KB |
1st lines differ - on the 1st token, expected: '6', found: '5' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
4952 KB |
1st lines differ - on the 1st token, expected: '6', found: '5' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
4952 KB |
1st lines differ - on the 1st token, expected: '6', found: '5' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
4952 KB |
1st lines differ - on the 1st token, expected: '6', found: '5' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
4952 KB |
1st lines differ - on the 1st token, expected: '6', found: '5' |
2 |
Halted |
0 ms |
0 KB |
- |