#include <bits/stdc++.h>
using namespace std;
inline char _gc() {
  static char buf[1 << 14], *p1 = buf, *p2 = buf;
  return (p1 == p2 &&
          (p2 = (p1 = buf) + fread(buf, 1, 1 << 14, stdin), p1 == p2))
             ? EOF
             : *p1++;
}
int read() {
  int x = 0, f = 1;
  char c = _gc();
  for (; !isdigit(c); c = _gc())
    if (c == '-') f = -1;
  for (; isdigit(c); c = _gc()) x = x * 10 + c - '0';
  return x * f;
}
const int MAXN = 1e5 + 5;
int nedge, head[MAXN];
struct Edge {
  int to, nxt;
} edge[MAXN << 1];
void add(int x, int y) {
  edge[++nedge].to = y;
  edge[nedge].nxt = head[x];
  head[x] = nedge;
}
int n, x[MAXN], y[MAXN], X, Y, siz[MAXN];
double ans;
void dfs(int k, int fa) {
  siz[k] = 1;
  for (int i = head[k]; i; i = edge[i].nxt) {
    int u = edge[i].to;
    if (u == fa) continue;
    dfs(u, k);
    siz[k] += siz[u];
    x[k] += x[u];
    ans += 1LL * siz[u] * y[k] * x[u];
  }
  ans += 1LL * (n - siz[k]) * y[k] * (X - x[k]);
}
int main() {
  n = read();
  for (int i = 1; i < n; i++) {
    int x = read(), y = read();
    add(x, y), add(y, x);
  }
  for (int i = 1; i <= n; i++) {
    x[i] = read(), y[i] = read();
    X += x[i], Y += y[i];
  }
  dfs(1, 0);
  printf("%.10lf", ans / X / Y);
}
