#include <bits/stdc++.h>
using namespace std;
struct line {
  long long m, k;
  line(long long _m, long long _k) : m(_m), k(_k) {}
  long long f(int x) { return m * x + k; }
};
struct LiChao {
  int l, r;
  line best = line(0ll, 1ll << 60);
  LiChao *ch[2]{};
  LiChao(int _l, int _r) : l(_l), r(_r) {}
  void insert(line i) {
    if (l == r - 1) {
      if (i.f(l) < best.f(l)) best = i;
      return;
    }
    int m = l + r >> 1;
    if (i.f(m) < best.f(m)) swap(best, i);
    if (!ch[0]) ch[0] = new LiChao(l, m), ch[1] = new LiChao(m, r);
    ch[i.m < best.m]->insert(i);
  }
  long long query(int x) {
    int m = l + r >> 1;
    if (ch[x >= m]) return min(best.f(x), ch[x >= m]->query(x));
    return best.f(x);
  }
  void release() {
    if (ch[0]) ch[0]->release(), ch[1]->release();
    delete this;
  }
};
vector<vector<int>> g;
vector<vector<line>> node;
vector<LiChao *> tree;
vector<int> a, b;
vector<long long> ans;
void dfs(int i, int p) {
  tree[i] = new LiChao(-100004, 100004);
  bool islf = true;
  for (int j : g[i]) {
    if (j == p) continue;
    islf = false;
    dfs(j, i);
    if (node[i].size() < node[j].size()) {
      for (line ln : node[i]) node[j].push_back(ln), tree[j]->insert(ln);
      tree[i]->release();
      tree[i] = tree[j];
      node[i].swap(node[j]);
    } else {
      for (line ln : node[j]) node[i].push_back(ln), tree[i]->insert(ln);
      tree[j]->release();
    }
  }
  ans[i] = islf ? 0 : tree[i]->query(a[i]);
  node[i].emplace_back(b[i], ans[i]);
  tree[i]->insert(node[i].back());
}
int main() {
  int n;
  cin >> n;
  a.resize(n), b.resize(n);
  for (int i = 0; i < n; ++i) cin >> a[i];
  for (int i = 0; i < n; ++i) cin >> b[i];
  g.resize(n), tree.resize(n), ans.resize(n), node.resize(n);
  for (int i = 0; i < n - 1; ++i) {
    int x, y;
    cin >> x >> y;
    --x, --y;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  dfs(0, -1);
  for (int i = 0; i < n; ++i) cout << ans[i] << ' ';
}
