func_code_string: #include <bits/stdc++.h>   using namespace std;   const long long inf = 1e18;   const int N = 300005;   vector<pair<int, int>> g[N];   int pre[N], vis[N], sz[N];   long long d[N];   void dfs1(int u, int fa) {     pre[u] = fa;     for (auto [v, w] : g[u]) {       if (v != fa) {         d[v] = d[u] + w;         dfs1(v, u);       }     }   }   long long dfs2(int u) {     long long ret = 0;     sz[u] = 1;     for (auto [v, w] : g[u]) {       if (!vis[v]) {         vis[v] = true;         ret = max(ret, dfs2(v) + w);         sz[u] += sz[v];       }     }     return ret;   }   int main(int argc, char *argv[]) {     std::ios_base::sync_with_stdio(false);     int n, m;     cin >> n >> m;     for (int i = 0; i < n - 1; i++) {       int u, v, w;       cin >> u >> v >> w;       g[u].emplace_back(v, w);       g[v].emplace_back(u, w);     }     dfs1(1, 0);     vector<int> path;     for (int i = n; i; i = pre[i]) path.push_back(i), vis[i] = 1;     reverse(path.begin(), path.end());     long long mx = -inf, now = dfs2(path[0]), now2 = -inf;     for (int i = 1; i < path.size(); i++) {       long long x = dfs2(path[i]);       if (sz[path[i]] > 2) x = inf;       if (now == 0 && x == 0) {         if (i > 1) {           mx = max(mx, now2 + x - (d[path[i]] - d[path[i - 1]]));         }       } else {         mx = max(mx, now + x - (d[path[i]] - d[path[i - 1]]));       }       now = now - (d[path[i]] - d[path[i - 1]]);       now2 = now;       now = max(now, x);     }     while (m--) {       long long x;       cin >> x;       if (x + mx >= 0)         cout << d[n] << endl;       else         cout << d[n] + x + mx << endl;     }     return 0;   }   