#include <bits/stdc++.h>
using namespace std;
const auto start_time = std::chrono::high_resolution_clock::now();
void timecalculater() {}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void __print(int x) { cout << x; }
void __print(long x) { cout << x; }
void __print(long long x) { cout << x; }
void __print(unsigned x) { cout << x; }
void __print(unsigned long x) { cout << x; }
void __print(unsigned long long x) { cout << x; }
void __print(float x) { cout << x; }
void __print(double x) { cout << x; }
void __print(long double x) { cout << x; }
void __print(char x) { cout << '\'' << x << '\''; }
void __print(const char *x) { cout << '\"' << x << '\"'; }
void __print(const string &x) { cout << '\"' << x << '\"'; }
void __print(bool x) { cout << (x ? "true" : "false"); }
template <typename T, typename V>
void __print(const pair<T, V> &x) {
  cout << '{';
  __print(x.first);
  cout << ',';
  __print(x.second);
  cout << '}';
}
template <typename T>
void __print(const T &x) {
  int f = 0;
  cout << '{';
  for (auto &i : x) cout << (f++ ? "," : ""), __print(i);
  cout << "}";
}
void _print() { cout << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) {
  __print(t);
  if (sizeof...(v)) cout << ", ";
  _print(v...);
}
long long p = 1e9 + 7;
const int N = 2e5 + 5;
const long long INF = 2e18;
long long eval(long long m, long long c, long long x) {
  if (m == -INF) return -INF;
  return m * x + c;
}
struct node {
  node *a[2];
  long long m, c;
};
long long n;
long long LO = -1e5, HI = 1e5;
node *getnode() {
  node *tree = new node();
  tree->m = -INF;
  tree->c = -INF;
  return tree;
}
void insert(node *tree, long long l, long long r, long long m, long long c) {
  long long mid = (l + r) / 2;
  bool lef = eval(m, c, l) > eval(tree->m, tree->c, l);
  bool mi = eval(m, c, mid) > eval(tree->m, tree->c, mid);
  if (mi) {
    swap(m, tree->m);
    swap(c, tree->c);
  }
  if (r == l) {
    return;
  }
  if (lef != mi) {
    if (tree->a[0] == NULL) {
      tree->a[0] = getnode();
      tree->a[0]->m = m;
      tree->a[0]->c = c;
    }
    insert(tree->a[0], l, mid, m, c);
  } else {
    if (mid + 1 > r) return;
    if (tree->a[1] == NULL) {
      tree->a[1] = getnode();
      tree->a[1]->m = m;
      tree->a[1]->c = c;
    }
    insert(tree->a[1], mid + 1, r, m, c);
  }
}
long long find(node *tree, long long l, long long r, long long x) {
  if (tree == NULL) {
    return -INF;
  }
  long long val = eval(tree->m, tree->c, x);
  if (r == l) {
    return val;
  }
  long long mid = (l + r) / 2;
  if (x < mid) {
    return max(val, find(tree->a[0], l, mid, x));
  }
  if (mid + 1 > r) return -INF;
  return max(val, find(tree->a[1], mid + 1, r, x));
}
long long a[N];
long long b[N];
long long ans[N];
long long sub[N];
vector<int> g[N];
node *tree;
void dfs1(int i, int p) {
  sub[i] = 1;
  for (auto j : g[i]) {
    if (j != p) {
      dfs1(j, i);
      sub[i] += sub[j];
    }
  }
}
void add(int i, int p) {
  insert(tree, LO, HI, -b[i], -ans[i]);
  for (auto j : g[i]) {
    if (j != p) {
      add(j, i);
    }
  }
}
void dfs(int i, int p, bool keep) {
  int mx = 0, big = -1;
  for (auto j : g[i]) {
    if (j != p) {
      if (mx < sub[j]) {
        mx = sub[j];
        big = j;
      }
    }
  }
  for (auto j : g[i]) {
    if (j != p && j != big) {
      dfs(j, i, 0);
    }
  }
  if (big != -1) {
    dfs(big, i, 1);
  }
  for (auto j : g[i]) {
    if (j != p && j != big) {
      add(j, i);
    }
  }
  ans[i] = (-find(tree, LO, HI, a[i]));
  if (big == -1) {
    ans[i] = 0;
  }
  insert(tree, LO, HI, -b[i], -ans[i]);
  if (!keep) {
    delete[] tree;
    tree = getnode();
  }
}
int main() {
  cin.sync_with_stdio(0);
  cin.tie(0);
  cin.exceptions(cin.failbit);
  ;
  int T = 1;
  while (T--) {
    cin >> n;
    for (int i = 0; i < (n); ++i) cin >> a[i + 1];
    for (int i = 0; i < (n); ++i) cin >> b[i + 1];
    for (int i = 0; i < (n - 1); ++i) {
      long long u, v;
      cin >> u >> v;
      g[u].push_back(v);
      g[v].push_back(u);
    }
    tree = getnode();
    dfs1(1, -1);
    dfs(1, -1, 1);
    for (int i = 0; i < (n); ++i) {
      cout << ans[i + 1] << " ";
    }
  }
  timecalculater();
  return 0;
}
