#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 100;
long long ans[N];
long long A[N], B[N];
int sz[N], big[N];
vector<int> Tree[N];
template <typename TT = long long>
struct LiChaoTree {
  const static TT INF = 1e18;
  const static TT MIN_Q = -1e5 - 1;
  const static TT MAX_Q = 1e5 + 1;
  struct SegNode {
    complex<TT> line;
    SegNode *left, *right;
    SegNode(complex<TT> _line = {0, INF}, SegNode* _left = NULL,
            SegNode* _right = NULL)
        : line(_line), left(_left), right(_right) {}
  } * root;
  vector<complex<TT>> lines;
  LiChaoTree() { root = NULL; }
  TT evaluate(complex<TT> line, TT x) { return line.real() * x + line.imag(); }
  void insert(complex<TT> line, SegNode*& node, TT L, TT R) {
    if (node == NULL) {
      node = new SegNode(line);
      return;
    }
    TT mid = (L + R) / 2;
    bool LP = evaluate(line, L) < evaluate(node->line, L);
    bool MP = evaluate(line, mid) < evaluate(node->line, mid);
    if (MP) swap(line, node->line);
    if (R - L == 1)
      return;
    else if (LP != MP)
      insert(line, node->left, L, mid);
    else
      insert(line, node->right, mid, R);
  }
  void insert(TT a, TT b) {
    lines.push_back(complex<TT>(a, b));
    insert(complex<TT>(a, b), root, MIN_Q, MAX_Q);
  }
  TT query(TT x, SegNode*& node, TT L, TT R) {
    if (node == NULL) return INF;
    TT mid = (L + R) / 2;
    TT res = evaluate(node->line, x);
    if (R - L == 1)
      return res;
    else if (x < mid)
      return min(res, query(x, node->left, L, mid));
    else
      return min(res, query(x, node->right, mid, R));
  }
  TT query(TT x) { return query(x, root, MIN_Q, MAX_Q); }
};
LiChaoTree<long long> CHT[N];
void preCalc(int u = 1, int p = 0) {
  sz[u] = 1;
  int maxChild = 0;
  for (auto v : Tree[u])
    if (v != p) {
      preCalc(v, u);
      sz[u] += sz[v];
      if (sz[v] > maxChild || !big[u]) {
        maxChild = sz[v];
        big[u] = v;
      }
    }
}
void DFS(int u = 1, int p = 0, bool keep = 0) {
  for (auto v : Tree[u])
    if (v != p && v != big[u]) DFS(v, u, 0);
  if (big[u]) {
    DFS(big[u], u, 1);
    swap(CHT[u], CHT[big[u]]);
  }
  for (auto v : Tree[u])
    if (v != p && v != big[u])
      for (auto line : CHT[v].lines) CHT[u].insert(line.real(), line.imag());
  if (CHT[u].root) ans[u] = CHT[u].query(A[u]);
  CHT[u].insert(B[u], ans[u]);
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%lld", A + i);
  for (int i = 1; i <= n; i++) scanf("%lld", B + i);
  for (int i = 1; i < n; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    Tree[u].push_back(v);
    Tree[v].push_back(u);
  }
  preCalc();
  DFS();
  for (int i = 1; i <= n; i++) printf("%lld ", ans[i]);
  puts("");
  return 0;
}
