#include "closing.h"
#include <bits/stdc++.h>
#include <vector>
#define MP make_pair
#define f first
#define s second
typedef long long ll;
using namespace std;
const int INF = (int)1e6;
int dijkstra(int N, int X, int Y, ll K, vector<vector<pair<ll,ll>>> &g, vector<ll> &alr) {
priority_queue <pair<ll,ll>, vector <pair<ll,ll>>, greater<pair<ll,ll>>> pq;
pq.push(MP(0, Y));
int ans = 0;
bool vis[N + 2];
for (int i = 0; i < N + 2; i++) vis[i] = false;
while (!pq.empty()) {
while (!pq.empty() && vis[pq.top().s]) pq.pop();
if (pq.empty()) break;
auto p = pq.top();
vis[p.s] = true;
if (K >= p.f) {
if (p.f > 0) K -= p.f;
ans++;
}
else break;
p.f += alr[p.s];
for (auto &it : g[p.s]) {
if (vis[it.f]) continue;
pq.push(MP(p.f + it.s - alr[it.f], it.f));
}
}
return ans;
}
ll eval(int l, int r, int nodo, ll K, vector<ll> &alr, vector <int> &W) {
ll acum = 0;
for (int i = nodo; i < r; i++) {
acum += W[i];
K -= acum;
alr[i + 1] = acum;
}
acum = 0;
for (int i = nodo - 1; i >= l; i--) {
acum += W[i];
K -= acum;
alr[i] = acum;
}
return K;
}
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 <vector <pair<ll,ll>>> g(N + 2);
for (int i = 0; i < N - 1; i++) {
g[U[i]].push_back(MP(V[i], W[i]));
g[V[i]].push_back(MP(U[i], W[i]));
}
vector <ll> alr(N + 2);
for (int i = 0; i < N + 2; i++) alr[i] = 0;
int ans = 2;
for (int i = 0; i < N; i++) {
if (i > X) break;
for (int j = i; j < N; j++) {
if (j < X) continue;
ll newK = eval(i, j, X, K, alr, W);
if (newK >= 0) ans = max(ans, j - i + 1 + dijkstra(N, X, Y, newK, g, alr));
for (int k = i; k <= j; k++) alr[k] = 0;
}
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 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 |
Execution timed out |
1028 ms |
21584 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Incorrect |
1 ms |
348 KB |
1st lines differ - on the 1st token, expected: '96', found: '92' |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Incorrect |
1 ms |
348 KB |
1st lines differ - on the 1st token, expected: '96', found: '92' |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Incorrect |
1 ms |
348 KB |
1st lines differ - on the 1st token, expected: '96', found: '92' |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 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 |
0 ms |
348 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 |
0 ms |
348 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 |
0 ms |
348 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 |
0 ms |
348 KB |
1st lines differ - on the 1st token, expected: '6', found: '5' |
2 |
Halted |
0 ms |
0 KB |
- |