# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
973507 | duckindog | Harbingers (CEOI09_harbingers) | C++17 | 1062 ms | 11956 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |