#include "closing.h"
#include <bits/stdc++.h>
#define MAX 200005
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
int visited[MAX];
vector<pii> graph[MAX];
ll dist1[MAX], dist2[MAX];
void dfs1(int node) {
visited[node] = 1;
for(auto [v, w] : graph[node]) {
if(visited[v]) continue;
dist1[v] = dist1[node] + w;
dfs1(v);
}
}
void dfs2(int node) {
visited[node] = 1;
for(auto [v, w] : graph[node]) {
if(visited[v]) continue;
dist2[v] = dist2[node] + w;
dfs2(v);
}
}
ll L[MAX], R[MAX];
ll mid[MAX];
ll ans[MAX], tmp[MAX];
ll c[MAX];
int max_score(int N, int X, int Y, long long K, vector<int> U, vector<int> V, vector<int> W)
{
for(int i = 0; i < N; ++i) graph[i].clear();
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]});
}
for(int i = 0; i < N; ++i) visited[i] = dist1[i] = 0;
dfs1(X);
for(int i = 0; i < N; ++i) visited[i] = dist2[i] = 0;
dfs2(Y);
for(int i = 0; i < N; ++i) c[i] = 0;
int p = X, q = Y, id = 1;
for(int i = 1; i <= 2 * N; ++i) mid[i] = (ll)(2e18);
while(true) {
if(q == X - 1 && p == Y + 1) break;
else if(q == X - 1) mid[id] = mid[id - 1] + dist1[p] - c[p], c[p] = dist1[p], ++p;
else if(p == Y + 1) mid[id] = mid[id - 1] + dist2[q] - c[q], c[q] = dist2[q], --q;
else if(dist1[p] - c[p] <= dist2[q] - c[q]) mid[id] = mid[id - 1] + dist1[p] - c[p], c[p] = dist1[p], ++p;
else mid[id] = mid[id - 1] + dist2[q] - c[q], c[q] = dist2[q], --q;
++id;
}
p = X, q = X, id = 1;
for(int i = 1; i <= 2 * N; ++i) L[i] = (ll)(2e18);
while(true) {
if(p == 0 && q == 0) break;
else if(p == q) --p, L[id] = L[id - 1] + dist1[p];
else if(p == 0) --q, L[id] = L[id - 1] + dist2[q] - dist1[q];
else {
if(dist2[q - 1] - dist1[q - 1] <= dist1[p - 1]) --q, L[id] = L[id - 1] + dist2[q] - dist1[q];
else --p, L[id] = L[id - 1] + dist1[p];
}
++id;
}
p = Y, q = Y, id = 1;
for(int i = 1; i <= 2 * N; ++i) R[i] = (ll)(2e18);
while(true) {
if(p == N - 1 && q == N - 1) break;
else if(p == q) ++p, R[id] = R[id - 1] + dist2[p];
else if(p == N - 1) ++q, R[id] = R[id - 1] + dist1[q] - dist2[q];
else {
if(dist1[q + 1] - dist2[q + 1] <= dist2[p + 1]) ++q, R[id] = R[id - 1] + dist1[q] - dist2[q];
else ++p, R[id] = R[id - 1] + dist2[p];
}
++id;
}
for(int i = 0; i <= 2 * N; ++i) tmp[i] = ans[i] = mid[i];
for(int i = 0; i <= 2 * N; ++i) for(int j = 0; j <= i; ++j) tmp[i] = min(tmp[i], ans[j] + L[i - j]);
for(int i = 0; i <= 2 * N; ++i) ans[i] = tmp[i];
for(int i = 0; i <= 2 * N; ++i) for(int j = 0; j <= i; ++j) tmp[i] = min(tmp[i], ans[j] + R[i - j]);
for(int i = 0; i <= 2 * N; ++i) ans[i] = tmp[i];
int mx = 0;
for(int i = 0; i <= 2 * N; ++i) if(ans[i] <= K) mx = i;
return mx;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
17240 KB |
1st lines differ - on the 1st token, expected: '6', found: '7' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1035 ms |
33616 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
17244 KB |
Output is correct |
2 |
Correct |
3 ms |
17240 KB |
Output is correct |
3 |
Correct |
3 ms |
17440 KB |
Output is correct |
4 |
Correct |
3 ms |
17244 KB |
Output is correct |
5 |
Correct |
3 ms |
17500 KB |
Output is correct |
6 |
Correct |
3 ms |
17244 KB |
Output is correct |
7 |
Correct |
3 ms |
17244 KB |
Output is correct |
8 |
Correct |
3 ms |
17500 KB |
Output is correct |
9 |
Correct |
3 ms |
17496 KB |
Output is correct |
10 |
Correct |
3 ms |
17244 KB |
Output is correct |
11 |
Correct |
3 ms |
17500 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
17244 KB |
Output is correct |
2 |
Correct |
3 ms |
17240 KB |
Output is correct |
3 |
Correct |
3 ms |
17440 KB |
Output is correct |
4 |
Correct |
3 ms |
17244 KB |
Output is correct |
5 |
Correct |
3 ms |
17500 KB |
Output is correct |
6 |
Correct |
3 ms |
17244 KB |
Output is correct |
7 |
Correct |
3 ms |
17244 KB |
Output is correct |
8 |
Correct |
3 ms |
17500 KB |
Output is correct |
9 |
Correct |
3 ms |
17496 KB |
Output is correct |
10 |
Correct |
3 ms |
17244 KB |
Output is correct |
11 |
Correct |
3 ms |
17500 KB |
Output is correct |
12 |
Correct |
3 ms |
17496 KB |
Output is correct |
13 |
Correct |
3 ms |
17500 KB |
Output is correct |
14 |
Correct |
3 ms |
17332 KB |
Output is correct |
15 |
Correct |
3 ms |
17496 KB |
Output is correct |
16 |
Correct |
3 ms |
17476 KB |
Output is correct |
17 |
Correct |
3 ms |
17500 KB |
Output is correct |
18 |
Correct |
3 ms |
17504 KB |
Output is correct |
19 |
Correct |
4 ms |
17476 KB |
Output is correct |
20 |
Correct |
4 ms |
17500 KB |
Output is correct |
21 |
Correct |
4 ms |
17500 KB |
Output is correct |
22 |
Correct |
4 ms |
17496 KB |
Output is correct |
23 |
Correct |
4 ms |
17496 KB |
Output is correct |
24 |
Correct |
4 ms |
17500 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
17244 KB |
Output is correct |
2 |
Correct |
3 ms |
17240 KB |
Output is correct |
3 |
Correct |
3 ms |
17440 KB |
Output is correct |
4 |
Correct |
3 ms |
17244 KB |
Output is correct |
5 |
Correct |
3 ms |
17500 KB |
Output is correct |
6 |
Correct |
3 ms |
17244 KB |
Output is correct |
7 |
Correct |
3 ms |
17244 KB |
Output is correct |
8 |
Correct |
3 ms |
17500 KB |
Output is correct |
9 |
Correct |
3 ms |
17496 KB |
Output is correct |
10 |
Correct |
3 ms |
17244 KB |
Output is correct |
11 |
Correct |
3 ms |
17500 KB |
Output is correct |
12 |
Correct |
3 ms |
17496 KB |
Output is correct |
13 |
Correct |
3 ms |
17500 KB |
Output is correct |
14 |
Correct |
3 ms |
17332 KB |
Output is correct |
15 |
Correct |
3 ms |
17496 KB |
Output is correct |
16 |
Correct |
3 ms |
17476 KB |
Output is correct |
17 |
Correct |
3 ms |
17500 KB |
Output is correct |
18 |
Correct |
3 ms |
17504 KB |
Output is correct |
19 |
Correct |
4 ms |
17476 KB |
Output is correct |
20 |
Correct |
4 ms |
17500 KB |
Output is correct |
21 |
Correct |
4 ms |
17500 KB |
Output is correct |
22 |
Correct |
4 ms |
17496 KB |
Output is correct |
23 |
Correct |
4 ms |
17496 KB |
Output is correct |
24 |
Correct |
4 ms |
17500 KB |
Output is correct |
25 |
Correct |
4 ms |
17500 KB |
Output is correct |
26 |
Correct |
37 ms |
17828 KB |
Output is correct |
27 |
Correct |
32 ms |
17756 KB |
Output is correct |
28 |
Correct |
35 ms |
18000 KB |
Output is correct |
29 |
Correct |
35 ms |
17752 KB |
Output is correct |
30 |
Correct |
32 ms |
17756 KB |
Output is correct |
31 |
Correct |
39 ms |
17756 KB |
Output is correct |
32 |
Correct |
37 ms |
17752 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
17240 KB |
1st lines differ - on the 1st token, expected: '6', found: '7' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
17240 KB |
1st lines differ - on the 1st token, expected: '6', found: '7' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
17240 KB |
1st lines differ - on the 1st token, expected: '6', found: '7' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
17240 KB |
1st lines differ - on the 1st token, expected: '6', found: '7' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
17240 KB |
1st lines differ - on the 1st token, expected: '6', found: '7' |
2 |
Halted |
0 ms |
0 KB |
- |