#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<vector<pair<ll,ll>>>graph;
vector<bool> vis;
void dfs(vector<ll> &dist, int x, ll d){
vis[x] = true;
dist[x] = d;
for (auto [y, w] : graph[x]){
if (!vis[y]){
dfs(dist, y, d + w);
}
}
}
int max_score(int N, int X, int Y, ll K, vector<int> U, vector<int> V, vector<int> W){
graph.assign(N,vector<pair<ll,ll>>());
for(int i=0;i<(N-1);i++){
graph[U[i]].push_back({V[i],W[i]});
graph[V[i]].push_back({U[i],W[i]});
}
//Calculo de distancia.
vis.assign(N,false);
vector<ll>distX(N);
dfs(distX,X,0);
vis.assign(N,false);
vector<ll>distY(N);
dfs(distY,Y,0);
vector<ll>closing(N,0);
vector<vector<bool>>v(2,vector<bool>(N));
priority_queue<tuple<ll,ll,ll>,vector<tuple<ll,ll,ll>>,greater<tuple<ll,ll,ll>>>prioridad;
int ans=0;
prioridad.push({0,X,0});
prioridad.push({0,Y,1});
while(!prioridad.empty()){
auto[cost,nodo,from]=prioridad.top();
prioridad.pop();
if((K+closing[nodo])>=cost){
K+=closing[nodo];
K-=cost;
closing[nodo]=cost;
v[from][nodo]=true;
ans++;
}
for(auto [vecino,no_importa]:graph[nodo]){
if(!v[vecino][from]&&from==0){
prioridad.push({distX[vecino],vecino,from});
}
else if(!v[vecino][from]&&from==1){
prioridad.push({distY[vecino],vecino,from});
}
}
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
348 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
91 ms |
56916 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
348 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
348 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
348 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
348 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
348 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
348 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
348 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
348 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |