#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define all(s) s.begin(), s.end()
#define rall(s) s.rbegin(), s.rend()
#define sz(s) (int)s.size()
#define F first
#define S second
#define endl '\n'
const int N = 1e5 + 11;
const int MXBIT = 20, MAXN = 3e6 + 7;
const int M = 100005;
const ll INF = 1e17;
struct Line {
ll m, b;
Line(ll _m = 0, ll _b = INF) : m(_m), b(_b) {
}
ll get(ll x) const { return m * x + b; }
};
struct PersistentLiChao {
struct Node {
Line line;
Node *left, *right;
Node(Line l) : line(l), left(nullptr), right(nullptr) {
}
Node(Line l, Node *L, Node *R) : line(l), left(L), right(R) {
}
};
ll lo, hi;
PersistentLiChao(ll _lo, ll _hi) : lo(_lo), hi(_hi) {
}
Node *insert(Node *node, ll l, ll r, Line newLine) {
if (!node) return new Node(newLine);
ll mid = l + (r - l) / 2;
Line low = node->line, high = newLine;
if (high.get(mid) < low.get(mid)) swap(low, high);
if (low.get(l) <= high.get(l) && low.get(r) <= high.get(r)) return new Node(low, node->left, node->right);
if (low.get(l) > high.get(l)) {
Node *L = insert(node->left, l, mid, high);
return new Node(low, L, node->right);
}
Node *R = insert(node->right, mid + 1, r, high);
return new Node(low, node->left, R);
}
Node *insert(Node *root, Line newLine) {
return insert(root, lo, hi, newLine);
}
ll query(Node *node, ll l, ll r, ll x) const {
if (!node) return INF;
ll res = node->line.get(x);
if (l == r) return res;
ll mid = l + (r - l) / 2;
if (x <= mid) return min(res, query(node->left, l, mid, x));
return min(res, query(node->right, mid + 1, r, x));
}
ll query(Node *root, ll x) const {
return query(root, lo, hi, x);
}
};
PersistentLiChao::Node *root[N];
PersistentLiChao cht(0, 1e9 + 7);
void solve() {
int n;
cin >> n;
vector<pair<int, int> > adj[n + 1];
for (int i{1}; i < n; ++i) {
int u, v, w;
cin >> u >> v >> w;
adj[u].emplace_back(v, w);
adj[v].emplace_back(u, w);
}
vector<int> a(n + 1), b(n + 1);
vector<ll> d(n + 1);
for (int i{2}; i <= n; ++i) cin >> a[i] >> b[i];
root[0] = cht.insert(nullptr, {0, 0});
vector<ll> dp(n + 1);
dp[0] = 0;
function<void(int, int, ll)> dfs = [&](int u, int p, ll s) {
dp[u] = cht.query(root[p], b[u]) + s * b[u] + a[u];
// cout << u << ' ' << dp[u] << ' ' << s << ' ' << p << endl;
root[u] = cht.insert(root[p], {-s, dp[u]});
for (auto &[v, w]: adj[u]) {
if (v == p) continue;
dfs(v, u, s + w);
}
};
dfs(1, 0, 0);
for (int i{2}; i <= n; ++i) cout << dp[i] << " ";
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int t = 1;
// cin >> t;
clock_t start = clock();
while (t--) solve();
clock_t end = clock();
double time_spent = (double) (end - start) / CLOCKS_PER_SEC;
return 0;
}