#include "closing.h"
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
const int lim=2e5+100;
using lint=long long;
using pii=pair<lint,lint>;
int n;
vector<pii>v[lim];
vector<int>ds;
void dfs(int node,int par){
for(auto[j,c]:v[node]){
if(j==par)continue;
ds[j]=ds[node]+c;
dfs(j,node);
}
}
vector<int>getdist(int root){
ds=vector<int>(n);
dfs(root,-1);
return ds;
}
int max_score(int N, int X, int Y, long long K,
std::vector<int> U, std::vector<int> V, std::vector<int> W)
{
n=N;
for(int i=0;i<n;i++){
v[i].clear();
}
for(int i=0;i<n-1;i++){
v[U[i]].pb({V[i],W[i]});
v[V[i]].pb({U[i],W[i]});
}
vector<int>dist1=getdist(X),dist2=getdist(Y);
if(2*K<dist1[Y]){
//case 1
priority_queue<pii,vector<pii>,greater<pii>>pq;
pq.push({0,X});
pq.push({0,Y});
bool vis[n]{};
int ans=0;
while(pq.size()){
auto[c,node]=pq.top();
pq.pop();
if(K<c)break;
vis[node]=1;
K-=c;
ans++;
for(auto[j,d]:v[node]){
if(vis[j])continue;
pq.push({c+d,j});
}
}
return ans;
}else{
//case 2 3 5 6
return -1;
}
return -1;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
4956 KB |
1st lines differ - on the 1st token, expected: '6', found: '-1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
124 ms |
29244 KB |
1st lines differ - on the 1st token, expected: '451', found: '-1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
4952 KB |
1st lines differ - on the 1st token, expected: '3', found: '-1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
4952 KB |
1st lines differ - on the 1st token, expected: '3', found: '-1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
4952 KB |
1st lines differ - on the 1st token, expected: '3', found: '-1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
4956 KB |
1st lines differ - on the 1st token, expected: '6', found: '-1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
4956 KB |
1st lines differ - on the 1st token, expected: '6', found: '-1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
4956 KB |
1st lines differ - on the 1st token, expected: '6', found: '-1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
4956 KB |
1st lines differ - on the 1st token, expected: '6', found: '-1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
4956 KB |
1st lines differ - on the 1st token, expected: '6', found: '-1' |
2 |
Halted |
0 ms |
0 KB |
- |