#include <bits/stdc++.h>
const int N = 100005;
int n, cnt, head[N], dot[N << 1], nxt[N << 1], fa[N], siz[N];
double in[N], out[N], si, so, ans;
int read() {
  int x = 0, f = 1;
  char s;
  while ((s = getchar()) < '0' || s > '9')
    if (s == '-') f = -1;
  while (s >= '0' && s <= '9') {
    x = (x << 1) + (x << 3) + (s ^ 48);
    s = getchar();
  }
  return x * f;
}
void addEdge(const int u, const int v) {
  dot[++cnt] = v, nxt[cnt] = head[u], head[u] = cnt;
}
void dfs(const int u) {
  siz[u] = 1;
  for (int i = head[u]; i; i = nxt[i]) {
    int v = dot[i];
    if (v == fa[u]) continue;
    fa[v] = u;
    dfs(v);
    siz[u] += siz[v];
    in[u] += in[v];
  }
}
int main() {
  n = read();
  for (int i = 1; i < n; ++i) {
    int u = read(), v = read();
    addEdge(u, v), addEdge(v, u);
  }
  for (int i = 1; i <= n; ++i) {
    in[i] = read(), out[i] = read();
    si += in[i];
    so += out[i];
  }
  for (int i = 1; i <= n; ++i) in[i] /= si;
  dfs(1);
  for (int u = 1; u <= n; ++u) {
    for (int i = head[u]; i; i = nxt[i]) {
      int v = dot[i];
      if (fa[u] == v)
        ans += (1 - in[u]) * (n - siz[u]) * out[u] / so;
      else
        ans += in[v] * siz[v] * out[u] / so;
    }
  }
  printf("%.11f\n", ans);
  return 0;
}
