#include <bits/stdc++.h>
std::vector<int> g[100009];
int Sx, Sy, r, Sa[100009], Sb[100009];
int s[100009], t[100009], a[100009], b[100009];
long long ans, sub[100009], sumSub[100009];
void dfs1(int x) {
  Sa[x] = a[x];
  Sb[x] = b[x];
  s[x] = 1;
  for (auto &y : g[x]) {
    if (y != t[x]) {
      t[y] = x;
      dfs1(y);
      s[x] += s[y];
      Sa[x] += Sa[y];
      Sb[x] += Sb[y];
      sumSub[x] += sub[y];
    }
  }
  sub[x] = 1LL * s[x] * Sa[x];
}
void dfs2(int x, long long Sub) {
  for (auto &y : g[x]) {
    if (y != t[x]) {
      ans += Sb[y] * (1LL * (Sa[r] - Sa[y]) * (s[r] - s[y]) -
                      (sumSub[x] - sub[y] + Sub));
      ans += (Sb[r] - Sb[y]) * (1LL * Sa[y] * s[y] - sumSub[y]);
      dfs2(y, 1LL * (s[r] - s[y]) * (Sa[r] - Sa[y]));
    }
  }
}
int main() {
  int n;
  fscanf(stdin, "%d", &n);
  for (int i = 1; i < n; i++) {
    int x, y;
    fscanf(stdin, "%d%d", &x, &y);
    g[x].push_back(y);
    g[y].push_back(x);
  }
  for (int i = 1; i <= n; i++) {
    fscanf(stdin, "%d%d", &a[i], &b[i]);
    Sx += a[i];
    Sy += b[i];
  }
  r = 1;
  dfs1(r);
  dfs2(r, 0);
  fprintf(stdout, "%.12f\n", ans / (double)(1LL * Sx * Sy));
  fclose(stdin);
  fclose(stdout);
  return 0;
}
