#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = (x << 1) + (x << 3) + ch - '0';
    ch = getchar();
  }
  return x * f;
}
const int maxn = 2e5 + 1e2;
const int maxm = 2 * maxn;
int point[maxn], nxt[maxm], to[maxm];
double val[maxn];
int size[maxn];
double st[maxn], ed[maxn];
int n, m;
double sumst, sumed;
int cnt;
double ans;
void addedge(int x, int y) {
  nxt[++cnt] = point[x];
  to[cnt] = y;
  point[x] = cnt;
}
void dfs(int x, int fa) {
  size[x] = 1;
  val[x] = st[x];
  for (int i = point[x]; i; i = nxt[i]) {
    int p = to[i];
    if (p == fa) continue;
    dfs(p, x);
    size[x] += size[p];
    val[x] += val[p];
  }
}
int main() {
  n = read();
  for (int i = 1; i < n; i++) {
    int x = read(), y = read();
    addedge(x, y);
    addedge(y, x);
  }
  for (int i = 1; i <= n; i++) {
    scanf("%lf%lf", &st[i], &ed[i]);
    sumst += st[i];
    sumed += ed[i];
  }
  for (int i = 1; i <= n; i++) {
    st[i] = st[i] / sumst;
    ed[i] = ed[i] / sumed;
  }
  dfs(1, 0);
  for (int x = 1; x <= n; x++) {
    for (int i = point[x]; i; i = nxt[i]) {
      int p = to[i];
      if (size[p] >= size[x])
        ans = ans + 1.0 * (1.0 - val[x]) * 1.0 * (1.0 * n - size[x]) * ed[x];
      else
        ans = ans + val[p] * 1.0 * size[p] * ed[x];
    }
  }
  printf("%.12lf", ans);
  return 0;
}
