#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);
priority_queue<pair<ll,ll>,vector<pair<ll,ll>>,greater<pair<ll,ll>>>prioridad;
for(int i=0;i<N;i++){
prioridad.push({distX[i],i});
}
for(int i=0;i<N;i++){
prioridad.push({distY[i],i});
}
int ans=0;
while(!prioridad.empty()){
ll peso=prioridad.top().first;
ll nodo=prioridad.top().second;
prioridad.pop();
if((K+closing[nodo])>peso){
K+=closing[nodo];
K-=peso;
closing[nodo]=peso;
ans++;
}
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
137 ms |
36692 KB |
Output is correct |
2 |
Correct |
144 ms |
40784 KB |
Output is correct |
3 |
Correct |
71 ms |
2896 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
1st lines differ - on the 1st token, expected: '3', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
1st lines differ - on the 1st token, expected: '3', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
1st lines differ - on the 1st token, expected: '3', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
1st lines differ - on the 1st token, expected: '3', found: '2' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
1st lines differ - on the 1st token, expected: '3', found: '2' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
1st lines differ - on the 1st token, expected: '3', found: '2' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
1st lines differ - on the 1st token, expected: '3', found: '2' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
1st lines differ - on the 1st token, expected: '3', found: '2' |
3 |
Halted |
0 ms |
0 KB |
- |