#include <bits/stdc++.h>
int n, m, i, j, u, v, first[100005], e[200005], next[200005], tope;
int x[100005], y[100005], sumx, sumy;
inline void link(int u0, int v0) {
  ++tope;
  e[tope] = v0;
  next[tope] = first[u0];
  first[u0] = tope;
  return;
}
long long ans;
int fa[100005], sum[100005], size[100005];
int q[100005], lq, rq;
inline void bfs() {
  memset(fa, 0, sizeof(fa));
  int i1;
  q[rq = 1] = 1;
  for (lq = 1; lq <= rq; ++lq) {
    for (i1 = first[q[lq]]; i1; i1 = next[i1]) {
      if (e[i1] == fa[q[lq]]) continue;
      q[++rq] = e[i1];
      fa[e[i1]] = q[lq];
    }
  }
  long long i2;
  for (lq = rq; lq >= 1; --lq) {
    sum[q[lq]] = x[q[lq]];
    size[q[lq]] = 1;
    i2 = 0;
    for (i1 = first[q[lq]]; i1; i1 = next[i1])
      if (e[i1] != fa[q[lq]])
        sum[q[lq]] += sum[e[i1]], size[q[lq]] += size[e[i1]],
            i2 += sum[e[i1]] * (long long)(size[e[i1]]);
    i2 += (sumx - sum[q[lq]]) * (long long)(n - size[q[lq]]);
    ans += i2 * y[q[lq]];
  }
  return;
}
int main() {
  scanf("%d", &n);
  memset(first, 0, sizeof(first));
  tope = 0;
  for (i = 1; i < n; ++i) {
    scanf("%d%d", &u, &v);
    link(u, v);
    link(v, u);
  }
  sumx = sumy = 0;
  for (i = 1; i <= n; ++i)
    scanf("%d%d", &x[i], &y[i]), sumx += x[i], sumy += y[i];
  ans = 0;
  bfs();
  printf("%.20lf", ans / (double)(sumx) / sumy);
  return 0;
}
