#include <bits/stdc++.h>
const int M = 100005;
int read() {
  int x = 0, flag = 1;
  char c;
  while ((c = getchar()) < '0' || c > '9')
    if (c == '-') flag = -1;
  while (c >= '0' && c <= '9')
    x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
  return x * flag;
}
int n, tot, f[M], siz[M];
double ans, sums, sumt, val[M], st[M], ed[M];
struct edge {
  int v, next;
  edge(int V = 0, int N = 0) : v(V), next(N) {}
} e[2 * M];
void dfs(int u, int fa) {
  siz[u] = 1;
  val[u] = st[u];
  for (int i = f[u]; i; i = e[i].next) {
    int v = e[i].v;
    if (v == fa) continue;
    dfs(v, u);
    siz[u] += siz[v];
    val[u] += val[v];
  }
}
signed main() {
  n = read();
  for (int i = 1; i < n; i++) {
    int u = read(), v = read();
    e[++tot] = edge(v, f[u]), f[u] = tot;
    e[++tot] = edge(u, f[v]), f[v] = tot;
  }
  for (int i = 1; i <= n; i++) {
    scanf("%lf %lf", &st[i], &ed[i]);
    sums += st[i];
    sumt += ed[i];
  }
  for (int i = 1; i <= n; i++) {
    st[i] = st[i] / sums;
    ed[i] = ed[i] / sumt;
  }
  dfs(1, 0);
  for (int u = 1; u <= n; u++)
    for (int i = f[u]; i; i = e[i].next) {
      int v = e[i].v;
      if (siz[v] >= siz[u])
        ans += (1 - val[u]) * (n - siz[u]) * ed[u];
      else
        ans += val[v] * siz[v] * ed[u];
    }
  printf("%.10lf\n", ans);
}
