Submission #973507

#TimeUsernameProblemLanguageResultExecution timeMemory
973507duckindogHarbingers (CEOI09_harbingers)C++17
20 / 100
1062 ms11956 KiB
#include <bits/stdc++.h> using namespace std; const int N = 100'000 + 10; int n; vector<pair<int, int>> ad[N]; int s[N], velocity[N]; int par[N], d[N]; long long dp[N]; void dfs(int u, int p = -1) { auto& ret = dp[u]; { int x = u; while (x) { ret = min(ret, dp[x] + (d[u] - d[x]) * velocity[u] + s[u]); x = par[x]; } } for (const auto& [v, w] : ad[u]) { if (v == p) continue; d[v] = d[u] + w; par[v] = u; dfs(v, u); } } int32_t main() { cin.tie(0)->sync_with_stdio(0); cin >> n; for (int i = 2; i <= n; ++i) { int u, v, w; cin >> u >> v >> w; ad[u].push_back({v, w}); ad[v].push_back({u, w}); } for (int i = 2; i <= n; ++i) cin >> s[i] >> velocity[i]; memset(dp, 40, sizeof dp); dp[1] = 0; dfs(1); for (int i = 2; i <= n; ++i) cout << dp[i] << " \n"[i == n]; }
#Verdict Execution timeMemoryGrader output
Fetching results...