/*
Mayoeba Yabureru
*/
#include "closing.h"
#include<bits/stdc++.h>
using namespace std;
int max_score(int n, int x, int y, long long k, vector<int> U, vector<int> V, vector<int> W) {
x ++, y ++;
vector dis(n + 1, vector<long long>(2));
vector<vector<pair<int, long long>>> gr(n + 1);
for (int i = 0; i < n - 1; i ++) {
int u = U[i] + 1, v = V[i] + 1, w = W[i];
gr[u].push_back({v, w});
gr[v].push_back({u, w});
}
function<void(int, int, int)> dfs = [&] (int v, int p, int wt) {
for (auto [u, w] : gr[v]) {
if (u == p) continue;
dis[u][wt] = dis[v][wt] + w;
dfs(u, v, wt);
}
};
dfs(x, 0, 0), dfs(y, 0, 1);
vector<int> vc, path, onpath(n + 1);
function<void(int, int)> go = [&] (int v, int p) {
vc.push_back(v);
if (v == y) path = vc;
for (auto [u, w] : gr[v]) {
if (u == p) continue;
go(u, v);
}
vc.pop_back();
};
go(x, 0);
long long minstart = 0, mn = 1e15;
for (int i = 1; i <= n; i ++) {
if (max(dis[i][0], dis[i][1]) < mn) {
minstart = i;
mn = max(dis[i][0], dis[i][1]);
}
}
for (auto x : path) {
onpath[x] += 1;
if (x == minstart) break;
}
for (int i = path.size() - 1; i >= 0; i --) {
int x = path[i];
onpath[x] += 2;
if (x == minstart) break;
}
int ans = 0;
function f = [&] {
vector<int> did(n + 1);
multiset<pair<long long, int>> s;
for (int i = 1; i <= n; i ++) {
s.insert({dis[i][0], i});
s.insert({dis[i][1], i});
}
int cnt = 0;
vector<int> v;
while (s.size()) {
auto [x, y] = *s.begin();
s.erase(s.begin());
if (did[y]) continue;
if (x > k) break;
k -= x;
did[y] = 1;
cnt ++;
}
if (k >= 0) return cnt;
return -100000000;
};
long long kk = k;
ans = f();
k = kk;
vector dp(n + 1, vector (2 * (n + 1), vector (2, vector<long long> (2, 1e18))));
vector dpp(2 * (n + 1), vector (2, vector<long long>(2)));
vector<int> siz(n + 1);
function<void(int, int)> calcsiz = [&] (int x, int p) {
siz[x] = 1;
for (auto [u, w] : gr[x]) {
if (u == p) continue;
calcsiz(u, x);
siz[x] += siz[u];
}
};
map<vector<int>, int> did;
calcsiz(minstart, 0);
function<void(int, int, int, int)> calc = [&] (int x, int p, int rx, int ry) {
if (did[{x, rx, ry}]) return;
did[{x, rx, ry}] = 1;
if (onpath[x] == 0) dp[x][0][rx][ry] = 0;
if (rx && (onpath[x] & 2) == 0) dp[x][1][rx][ry] = min(dp[x][1][rx][ry], dis[x][0]);
if (ry && (onpath[x] & 1) == 0) dp[x][1][rx][ry] = min(dp[x][1][rx][ry], dis[x][1]);
if (rx && ry) dp[x][2][rx][ry] = min(dp[x][2][rx][ry], max(dis[x][0], dis[x][1]));
int sumsiz = 1;
for (auto [u, w] : gr[x]) {
if (u == p) continue;
calc(u, x, rx, ry);
if (rx && ry) {
if (onpath[u] == 0) calc(u, x, 0, 0);
if (onpath[u] != 1) calc(u, x, 0, 1);
if (onpath[u] != 2) calc(u, x, 1, 0);
}
else if (rx && onpath[u] != 1) calc(u, x, 0, ry);
else if (ry && onpath[u] != 2) calc(u, x, rx, 0);
dpp = dp[x];
for (int i = 0; i <= 1; i ++) {
for (int j = 0; j <= 1; j ++) {
for (int z = 2 * siz[u]; z >= 0; z --) {
if (dp[u][z][i][j] == 1e18) continue;
for (int k = 2 * sumsiz; k >= 0; k --) {
dpp[k + z][rx][ry] = min(dpp[k + z][rx][ry], dp[x][k][rx][ry] + dp[u][z][i][j]);
}
}
}
}
sumsiz += siz[u];
for (int z = 0; z <= 2 * sumsiz; z ++) {
dp[x][z][rx][ry] = dpp[z][rx][ry];
dpp[z][rx][ry] = 0;
}
}
};
calc(minstart, 0, 1, 1);
for (int i = 0; i <= 2 * n; i ++) {
if (k >= dp[minstart][i][1][1]) ans = max(ans, i);
}
return ans;
}
/*
2
7 0 2 10
0 1 2
0 3 3
1 2 4
2 4 2
2 5 5
5 6 3
4 0 3 20
0 1 18
1 2 1
2 3 19
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1103 ms |
1384520 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
2 ms |
1116 KB |
Output is correct |
7 |
Correct |
1 ms |
1116 KB |
Output is correct |
8 |
Correct |
1 ms |
1116 KB |
Output is correct |
9 |
Correct |
1 ms |
860 KB |
Output is correct |
10 |
Incorrect |
2 ms |
1112 KB |
1st lines differ - on the 1st token, expected: '44', found: '52' |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
2 ms |
1116 KB |
Output is correct |
7 |
Correct |
1 ms |
1116 KB |
Output is correct |
8 |
Correct |
1 ms |
1116 KB |
Output is correct |
9 |
Correct |
1 ms |
860 KB |
Output is correct |
10 |
Incorrect |
2 ms |
1112 KB |
1st lines differ - on the 1st token, expected: '44', found: '52' |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
2 ms |
1116 KB |
Output is correct |
7 |
Correct |
1 ms |
1116 KB |
Output is correct |
8 |
Correct |
1 ms |
1116 KB |
Output is correct |
9 |
Correct |
1 ms |
860 KB |
Output is correct |
10 |
Incorrect |
2 ms |
1112 KB |
1st lines differ - on the 1st token, expected: '44', found: '52' |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
2 ms |
1116 KB |
Output is correct |
8 |
Correct |
1 ms |
1116 KB |
Output is correct |
9 |
Correct |
1 ms |
1116 KB |
Output is correct |
10 |
Correct |
1 ms |
860 KB |
Output is correct |
11 |
Incorrect |
2 ms |
1112 KB |
1st lines differ - on the 1st token, expected: '44', found: '52' |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
2 ms |
1116 KB |
Output is correct |
8 |
Correct |
1 ms |
1116 KB |
Output is correct |
9 |
Correct |
1 ms |
1116 KB |
Output is correct |
10 |
Correct |
1 ms |
860 KB |
Output is correct |
11 |
Incorrect |
2 ms |
1112 KB |
1st lines differ - on the 1st token, expected: '44', found: '52' |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
2 ms |
1116 KB |
Output is correct |
8 |
Correct |
1 ms |
1116 KB |
Output is correct |
9 |
Correct |
1 ms |
1116 KB |
Output is correct |
10 |
Correct |
1 ms |
860 KB |
Output is correct |
11 |
Incorrect |
2 ms |
1112 KB |
1st lines differ - on the 1st token, expected: '44', found: '52' |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
2 ms |
1116 KB |
Output is correct |
8 |
Correct |
1 ms |
1116 KB |
Output is correct |
9 |
Correct |
1 ms |
1116 KB |
Output is correct |
10 |
Correct |
1 ms |
860 KB |
Output is correct |
11 |
Incorrect |
2 ms |
1112 KB |
1st lines differ - on the 1st token, expected: '44', found: '52' |
12 |
Halted |
0 ms |
0 KB |
- |