#include "closing.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 5e2 + 10;
vector < pair < int, ll > > adj[maxn];
ll dist[2][maxn];
int n;
void bfs(int s, ll arr[])
{
queue < int > q;
for (int i = 0; i < n; i ++)
arr[i] = -1;
arr[s] = 0;
q.push(s);
while(!q.empty())
{
int v = q.front();
q.pop();
for (pair < int, ll > nb : adj[v])
{
if (arr[nb.first] == -1)
{
arr[nb.first] = arr[v] + nb.second;
q.push(nb.first);
}
}
}
}
const ll inf = 1e18;
ll value[maxn];
ll dp[maxn][maxn * 2][2][2], sub[maxn], temp[maxn * 2][2][2];
int used[maxn];
/**
*/
void dfs(int v)
{
///cout << "dfs " << v << endl;
sub[v] = 1;
used[v] = 1;
for (int j = 0; j <= 2; j ++)
for (int d = 0; d < 2; d ++)
for (int z = 0; z < 2; z ++)
dp[v][j][d][z] = inf;
dp[v][0][0][0] = 0;
dp[v][1][1][0] = dist[0][v];
dp[v][1][0][1] = dist[1][v];
dp[v][2][1][1] = max(dist[0][v], dist[1][v]);
for (pair < int, ll > nb : adj[v])
{
if (used[nb.first])
continue;
dfs(nb.first);
int u = nb.first;
for (int i = 0; i <= (sub[u] + sub[v]) * 2; i ++)
for (int x = 0; x < 2; x ++)
for (int y = 0; y < 2; y ++)
temp[i][x][y]= inf;
for (int i = 0; i <= sub[v] * 2; i ++)
for (int j = 0; j <= sub[u] * 2; j ++)
for (int d = 0; d < 2; d ++)
for (int z = 0; z < 2; z ++)
for (int x = 0; x <= d; x ++)
for (int y = 0; y <= z; y ++)
{
temp[i + j][d][z] = min(temp[i + j][d][z], dp[v][i][d][z] + dp[u][j][x][y]);
}
for (int i = 0; i <= (sub[v] + sub[u]) * 2; i ++)
for (int x = 0; x < 2; x ++)
for (int y = 0; y < 2; y ++)
dp[v][i][x][y] = temp[i][x][y];
sub[v] += sub[u];
}
}
vector < int > path;
bool get_path(int v, int p, int target)
{
if (v == target)
{
path.push_back(v);
return true;
}
for (pair < int, ll > nb : adj[v])
{
if (nb.first == p)
continue;
if (get_path(nb.first, v, target))
{
path.push_back(v);
return true;
}
}
return false;
}
ll sum_dp[maxn * 2], tp[maxn * 2];
ll cur_sz = 0;
void unite(int v, int d, int z)
{
/**cout << "unite " << endl;
for (int i = 0; i <= sub[v] * 2; i ++)
cout << dp[v][i][d][z]<< " ";
cout << endl;*/
for (int i = 0; i <= (cur_sz + sub[v]) * 2; i ++)
{
tp[i] = inf;
}
for (int j = 0; j <= 2 * cur_sz; j ++)
for (int i = 0; i <= 2 * sub[v]; i ++)
{
tp[i + j] = min(tp[i + j], sum_dp[j] + dp[v][i][d][z]);
}
for (int i = 0; i <= (cur_sz + sub[v]) * 2; i ++)
sum_dp[i] = tp[i];
cur_sz += sub[v];
}
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 ++)
{
dist[0][i] = dist[1][i] = 0;
adj[i].clear();
used[i] = 0;
value[i] = 0;
}
n = N;
for (int i = 0; i < N - 1; i ++)
{
adj[U[i]].push_back({V[i], W[i]});
adj[V[i]].push_back({U[i], W[i]});
}
bfs(X, dist[0]);
bfs(Y, dist[1]);
path.clear();
get_path(Y, -1, X);
for (int cur : path)
used[cur] = 1;
for (int cur : path)
{
dfs(cur);
}
/**for (int cur : path)
{
cout << "step " << cur << endl;
for (int j = 0; j <= sub[cur] * 2; j ++)
cout << dp[cur][j][1][0] << " ";
cout << endl;
}
cout << "sub " << sub[2] << endl;
cout << "-----------------" << endl;*/
int sz = path.size(), ans = 0;
for (int i = 0; i < sz; i ++)
{
///cout << "step " << i << endl;
int j = 0;
for (int j = 0; j < sz; j ++)
{
cur_sz = 0;
for (int i = 0; i <= N * 2; i ++)
sum_dp[i] = inf;
sum_dp[0] = 0;
for (int id = 0; id < sz; id ++)
{
unite(path[id], (id <= i), (id >= j));
}
int tek = 0 ;
for (int i = 0; i <= N * 2; i ++)
{
if (sum_dp[i] <= K)
ans = max(ans, i), tek = max(tek, i);
}
if (tek < last)
break;
last = tek;
///cout << j << " : " << ans << endl;
/**cout << "step " << i << " " << j << endl;
for (int i = 0; i <= N * 2; i ++)
cout << sum_dp[i] << " ";
cout << endl;*/
}
}
return ans;
}
Compilation message
closing.cpp: In function 'int max_score(int, int, int, long long int, std::vector<int>, std::vector<int>, std::vector<int>)':
closing.cpp:199:23: error: 'last' was not declared in this scope
199 | if (tek < last)
| ^~~~
closing.cpp:201:13: error: 'last' was not declared in this scope
201 | last = tek;
| ^~~~
closing.cpp:181:13: warning: unused variable 'j' [-Wunused-variable]
181 | int j = 0;
| ^