#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
int n, i, j, u, v;
long long ans, sum[maxn];
int X[maxn], Y[maxn], Xsum, Ysum;
int lx[maxn], rx[maxn], fa[maxn], dfn;
int pt[maxn << 1], nt[maxn << 1], hd[maxn], ecnt;
void dfs(int x, int f) {
  int i;
  fa[x] = f;
  lx[x] = ++dfn;
  sum[dfn] = sum[dfn - 1] + X[x];
  for (i = hd[x]; i; i = nt[i])
    if (pt[i] != f) dfs(pt[i], x);
  rx[x] = dfn;
}
void ins(int u, int v) {
  pt[++ecnt] = v;
  nt[ecnt] = hd[u];
  hd[u] = ecnt;
}
long long ex(int l, int r) { return sum[n] - sum[r] + sum[l - 1]; }
long long in(int l, int r) { return sum[r] - sum[l - 1]; }
int Ex(int l, int r) { return n - r + l - 1; }
int In(int l, int r) { return r - l + 1; }
int main() {
  scanf("%d", &n);
  for (i = 1; i < n; i++) {
    scanf("%d%d", &u, &v);
    ins(u, v);
    ins(v, u);
  }
  for (i = 1; i <= n; i++)
    scanf("%d%d", &X[i], &Y[i]), Xsum += X[i], Ysum += Y[i];
  dfs(1, 0);
  for (i = 1; i <= n; i++) {
    for (j = hd[i]; j; j = nt[j])
      if (pt[j] != fa[i])
        ans -= ex(lx[pt[j]], rx[pt[j]]) * In(lx[pt[j]], rx[pt[j]]) * Y[i];
    ans -= in(lx[i], rx[i]) * Ex(lx[i], rx[i]) * Y[i];
    ans += 1LL * Xsum * Y[i] * n;
  }
  printf("%.10f\n", 1. * ans / Xsum / Ysum - 1.);
  return 0;
}
