#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0;
  bool op = 0;
  char c = getchar();
  while (!isdigit(c)) op |= (c == '-'), c = getchar();
  while (isdigit(c)) x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
  return op ? -x : x;
}
const int N = 100010;
int n, tot, sx, sy;
int head[N], nxt[N * 2], to[N * 2], x[N], y[N], sz[N];
double f[N], g[N];
void addedge(int u, int v) {
  to[++tot] = v;
  nxt[tot] = head[u];
  head[u] = tot;
}
void dfs1(int u, int fa) {
  sz[u] = 1;
  for (int i = head[u]; i; i = nxt[i]) {
    if (to[i] == fa) continue;
    dfs1(to[i], u);
    sz[u] += sz[to[i]];
    f[u] += f[to[i]];
  }
  f[u] += 1.0 * (n - sz[u]) * y[u] / sy;
  return;
}
void dfs2(int u, int fa) {
  for (int i = head[u]; i; i = nxt[i]) {
    if (to[i] == fa) continue;
    double x = g[u] - 1.0 * (n - sz[to[i]]) * y[to[i]] / sy;
    g[to[i]] = x + 1.0 * sz[to[i]] * y[u] / sy;
    dfs2(to[i], u);
  }
  return;
}
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++) {
    x[i] = read();
    y[i] = read();
    sx += x[i];
    sy += y[i];
  }
  dfs1(1, 0);
  g[1] = f[1];
  dfs2(1, 0);
  double ans = 0;
  for (int i = 1; i <= n; i++) ans += g[i] * x[i] / sx;
  printf("%.12lf", ans);
  return 0;
}
