#include "closing.h"
#include "grader.cpp"
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
int max_score(int n, int x, int y, long long k, vector<int> U, vector<int> V, vector<int> W) {
vector<vector<pair<int, int>>> adj(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]});
}
vector<vector<i64>> dis(n, vector<i64>(2, 0));
function<void(int, int, int)> dfs = [&](int u, int p, int t) {
for (auto [v, w] : adj[u]) {
if (v == p) continue;
dis[v][t] = dis[u][t] + w;
dfs(v, u, t);
}
};
dfs(x, -1, 0);
dfs(y, -1, 1);
int ans = 2;
vector<vector<int>> used(n, vector<int>(2, 0));
used[x][0] = 1;
used[y][1] = 1;
for (int c = 1; c <= 2 * n; ++c) {
i64 mn = 1e18;
int from, type;
for (int u = 0; u < n; ++u) {
for (auto [v, w] : adj[u]) {
for (int t = 0; t <= 1; ++t) {
if (used[v][t] && used[u][t] == 0) {
if (mn > dis[u][t]) {
from = u;
type = t;
}
mn = min(mn, dis[u][t]);
}
}
}
}
if (mn <= k) {
k -= mn;
used[from][type] = 1;
dis[from][!type] -= mn;
++ans;
} else {
break;
}
}
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:47:28: warning: 'type' may be used uninitialized in this function [-Wmaybe-uninitialized]
47 | used[from][type] = 1;
| ^
closing.cpp:47:22: warning: 'from' may be used uninitialized in this function [-Wmaybe-uninitialized]
47 | used[from][type] = 1;
| ^
/usr/bin/ld: /tmp/ccg75YrO.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccMbkRNQ.o:closing.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status