// nxt[state][Alice-play][Bob-play][Alice-draw][Bob-draw] int nxt[100][3][3][3][3];
voidsolve(){ #pragma region pre
int tot = 0; for(int r = 0; r <= 3; ++r){ for(int s = 0; r + s <= 3; ++s){ int p = 3 - r - s; int code = r * 16 + s * 4 + p; handId[code] = tot++; hand[handId[code]] = {r, s, p}; } }
auto encode = [&](const std::vector<int>& H) -> int { return H[0] * 16 + H[1] * 4 + H[2]; };
memset(nxtId, -1, sizeof(nxtId));
for(int id = 0; id < 10; ++id){ for(int play = 0; play < 3; ++play){ if(!hand[id][play]) continue; for(int draw = 0; draw < 3; ++draw){ auto H = hand[id]; --H[play], ++H[draw]; nxtId[id][play][draw] = handId[encode(H)]; } } }
memset(nxt, -1, sizeof(nxt));
for(int state = 0; state < 100; ++state){ int aId = state / 10, bId = state % 10; for(int ap = 0; ap < 3; ++ap){ if(!hand[aId][ap]) continue; for(int bp = 0; bp < 3; ++bp){ if(!hand[bId][bp]) continue; for(int ad = 0; ad < 3; ++ad){ for(int bd = 0; bd < 3; ++bd){ int nA = nxtId[aId][ap][ad]; int nB = nxtId[bId][bp][bd]; nxt[state][ap][bp][ad][bd] = nA * 10 + nB; } } } } } #pragma endregion
auto score = [&](int a, int b) -> int { if(a == b) return1; if(a == 0and b == 1) return3; if(a == 1and b == 2) return3; if(a == 2and b == 0) return3; return0; };
voidsolve(){ int n = read(), a = read(), b = read(); #define popcount __builtin_popcount int pa = popcount(a), pb = popcount(b); if((pa & 1) ^ (pb & 1)) returnputs("No"), void();
voidsolve(){ int n = read(); structEdge {int v, w;}; std::vector<std::vector<Edge>> adj(n + 1); int W = 0; for(int i = 1; i < n; ++i){ int u = read(), v = read(), w = read(); adj[u].push_back({v, w}); adj[v].push_back({u, w}); W = max(W, w); } std::vector<std::vector<int>> dp(n + 1, std::vector<int>(W << 1, 0));
auto dfs = [&](auto&& self, int x, int p) -> void { for(auto& [y, w] : adj[x]){ if(y == p) continue; self(self, y, x); for(int i = 0; i < (W << 1); ++i){ ll tmp = INT_MAX; if(i >= w) tmp = min(tmp, max(0, dp[y][i - w] - w)); tmp = min(tmp, dp[y][min(i + w, 2 * W - 1)] + w); dp[x][i] = max(dp[x][i], tmp); } } }; dfs(dfs, 1, 0);
for(int u = 1; u <= n; ++u){ ll ans = INT_MAX; for(int i = 0; i < (W << 1); ++i) ans = min(ans, dp[u][i] + i); printf("%d ", ans); } puts(""); }