#include <bits/stdc++.h>
using namespace std;
template <typename T>
using point = std::complex<T>;
template <typename T>
T cross(const point<T> &a, const point<T> &b) {
  return std::imag(std::conj(a) * b);
}
template <typename T>
T dot(const point<T> &a, const point<T> &b) {
  return std::real(std::conj(a) * b);
}
template <typename T, int turn>
class half_hull : public std::vector<point<T>> {
  using std::vector<point<T>>::vector;

 public:
  point<T> extreme(const point<T> &p) const {
    assert(!this->empty());
    auto data = this->data();
    auto lo = 0, hi = (int)this->size() - 1;
    while (lo < hi) {
      int mid = (lo + hi) / 2;
      if (dot(p, data[mid] - data[mid + 1]) <= 0)
        lo = mid + 1;
      else
        hi = mid;
    }
    return data[lo];
  }
};
template <typename T, int turn>
half_hull<T, turn> merge(const half_hull<T, turn> &lhs,
                         const half_hull<T, turn> &rhs) {
  half_hull<T, turn> h;
  auto comp = [](const point<T> &a, const point<T> &b) {
    if (std::real(a) != std::real(b)) return std::real(a) < std::real(b);
    return std::imag(a) < std::imag(b);
  };
  auto add_point = [&](const point<T> &p) {
    while (h.size() >= 2 &&
           turn * cross(h.end()[-1] - h.end()[-2], p - h.end()[-2]) >= 0)
      h.pop_back();
    h.emplace_back(p);
  };
  for (auto a = lhs.begin(), b = rhs.begin(); a != lhs.end() || b != rhs.end();)
    add_point(a == lhs.end() || (b != rhs.end() && comp(*b, *a)) ? *b++ : *a++);
  return h;
}
template <typename T>
struct convex_hull_trick {
  void insert(const point<T> &p) {
    half_hull<T, +1> upper(1, p);
    half_hull<T, -1> lower(1, p);
    for (std::size_t i = 0; i < upper_hull.size(); ++i)
      if (upper_hull[i].empty()) {
        upper_hull[i].swap(upper);
        lower_hull[i].swap(lower);
        break;
      } else {
        upper = merge(upper, upper_hull[i]);
        lower = merge(lower, lower_hull[i]);
        upper_hull[i].clear();
        lower_hull[i].clear();
      }
    if (!lower.empty()) {
      upper_hull.emplace_back(upper);
      lower_hull.emplace_back(lower);
    }
  }
  point<T> extreme(const point<T> &p) const {
    if (std::imag(p) < 0) return extreme(lower_hull, p);
    return extreme(upper_hull, p);
  }
  void swap(convex_hull_trick &other) {
    upper_hull.swap(other.upper_hull);
    lower_hull.swap(other.lower_hull);
  }

 private:
  std::vector<half_hull<T, +1>> upper_hull;
  std::vector<half_hull<T, -1>> lower_hull;
  template <int turn>
  static point<T> extreme(const std::vector<half_hull<T, turn>> &hull,
                          const point<T> &p) {
    auto a = hull.begin();
    while (a != hull.end() && a->empty()) ++a;
    assert(a != hull.end());
    point<T> best = a->extreme(p);
    for (++a; a != hull.end(); ++a)
      if (!a->empty()) {
        auto q = a->extreme(p);
        if (dot(p, best - q) < 0) best = q;
      }
    return best;
  }
};
struct data {
  using Point = point<long double>;
  convex_hull_trick<long double> cht;
  vector<Point> ps;
  int size() const { return ps.size(); }
  void swap(data &other) {
    cht.swap(other.cht);
    ps.swap(other.ps);
  }
  void add_point(Point p) {
    cht.insert(p);
    ps.emplace_back(p);
  }
  long long query(Point p) const {
    Point q = cht.extreme(p);
    return llround(dot(p, q));
  }
};
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n), b(n);
  for (int i = 0; i < n; ++i) cin >> a[i];
  for (int i = 0; i < n; ++i) cin >> b[i];
  vector<vector<int>> g(n);
  for (int i = 1; i < n; ++i) {
    int u, v;
    cin >> u >> v;
    --u, --v;
    g[u].emplace_back(v);
    g[v].emplace_back(u);
  }
  vector<long long> dp(n);
  function<data(int, int)> dfs = [&](int u, int p) {
    data current;
    for (int v : g[u])
      if (v != p) {
        data child = dfs(v, u);
        if (child.size() > current.size()) child.swap(current);
        for (auto pt : child.ps) current.add_point(pt);
      }
    if (current.size()) dp[u] = -current.query(point<long double>(-a[u], -1));
    current.add_point(point<long double>(b[u], dp[u]));
    return current;
  };
  dfs(0, -1);
  for (int i = 0; i < n; ++i) cout << dp[i] << " \n"[i + 1 == n];
  return 0;
}
