#include <iostream>
#include <vector>
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define int long long
struct node {
int p, s; // prep, speed
};
int32_t main() {
freopen("harbingers.in", "r", stdin);
freopen("harbingers.out", "w", stdout);
ios::sync_with_stdio(0); cin.tie(0);
int n; cin >> n;
vector<vector<pair<int, int>>> g(n);
vector<node> nodes(n + 1);
vector<pair<int, int>> pr(n); // parent
for (int i = 0; i < n - 1; i++) {
int a, b, c; cin >> a >> b >> c, a--, b--;
if (a > b) swap(a, b);
g[a].emplace_back(b, c);
g[b].emplace_back(a, c);
pr[b] = {a, c};
}
for (int i = 1; i <= n - 1; i++) {
int p, s; cin >> p >> s;
nodes[i] = node{p, s};
}
function<int(int, int)> f = [&](int node, int har) {
if (node == 0) return 0ll;
int st = nodes[node].p + pr[node].second * nodes[node].s;
int nd = nodes[har].s * pr[node].second;
if (node == har) {
return st + f(pr[node].first, node);
}
if (st < nd) {
return st + f(pr[node].first, node);
} else {
return nd + f(pr[node].first, har);
}
};
for (int i = 1; i <= n - 1; i++) {
cout << f(i, i) << " ";
}
cout << '\n';
}
Compilation message
harbingers.cpp: In function 'int32_t main()':
harbingers.cpp:14:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
14 | freopen("harbingers.in", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
harbingers.cpp:15:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
15 | freopen("harbingers.out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
3 ms |
588 KB |
Execution killed with signal 11 |
2 |
Runtime error |
3 ms |
588 KB |
Execution killed with signal 11 |
3 |
Runtime error |
3 ms |
588 KB |
Execution killed with signal 11 |
4 |
Runtime error |
3 ms |
588 KB |
Execution killed with signal 11 |
5 |
Runtime error |
3 ms |
536 KB |
Execution killed with signal 11 |
6 |
Runtime error |
3 ms |
588 KB |
Execution killed with signal 11 |
7 |
Runtime error |
3 ms |
588 KB |
Execution killed with signal 11 |
8 |
Runtime error |
3 ms |
588 KB |
Execution killed with signal 11 |
9 |
Runtime error |
3 ms |
588 KB |
Execution killed with signal 11 |
10 |
Runtime error |
3 ms |
588 KB |
Execution killed with signal 11 |