#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int n;
double ans = 0, sx[N], sy[N], t[N], x[N], y[N], a, b, siz[N];
vector<int> g[N];
void adde(int u, int v) { g[u].push_back(v); }
void dfs(int u, int fa) {
  sx[u] = x[u], sy[u] = y[u];
  siz[u] = 1;
  for (int i = 0; i < (int)g[u].size(); i++) {
    int v = g[u][i];
    if (v == fa) continue;
    dfs(v, u);
    sx[u] += sx[v];
    sy[u] += sy[v];
    siz[u] += siz[v];
  }
  ans += sy[u] * (a - sx[u]);
  ans += sx[u] * (b - sy[u]);
  double tmp = siz[fa], tx = sx[fa], ty = sy[fa];
  siz[fa] = n - siz[u];
  sx[fa] = (a - sx[u]), sy[fa] = (b - sy[u]);
  double p = x[u] / 2;
  double sum1 = 0, sum2 = 0;
  for (int i = 0; i < (int)g[u].size(); i++) {
    int v = g[u][i];
    ans += p * sy[v] * (n - siz[v] - 1) * 2;
    sum1 += sy[v], sum2 += sy[v] * (n - 1 - siz[v]);
  }
  for (int i = 0; i < (int)g[u].size(); i++) {
    int v = g[u][i];
    ans += -siz[v] * sx[v] * (sum1 - sy[v]) +
           sx[v] * (sum2 - (n - 1 - siz[v]) * sy[v]);
  }
  siz[fa] = tmp;
  sx[fa] = tx, sy[fa] = ty;
  return;
}
int main() {
  scanf("%d", &n);
  int u, v;
  for (int i = 1; i < n; i++) {
    scanf("%d%d", &u, &v);
    adde(u, v), adde(v, u);
  }
  a = b = 0;
  for (int i = 1; i <= n; i++)
    scanf("%lf%lf", &x[i], &y[i]), a += x[i], b += y[i];
  dfs(1, 0);
  printf("%.10lf\n", ans / a / b);
  return 0;
}
