#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int r, s = 0, c;
  for (; !isdigit(c = getchar()); s = c)
    ;
  for (r = c ^ 48; isdigit(c = getchar()); (r *= 10) += c ^ 48)
    ;
  return s ^ 45 ? r : -r;
}
struct edge {
  int to, next;
} mem[110000 << 1];
int head[110000], cnt = 1;
inline void add(int u, int v) {
  mem[++cnt].next = head[u];
  mem[cnt].to = v;
  head[u] = cnt;
}
int n, u, v;
int x[110000], y[110000], f[110000], size[110000];
double s[110000], p[110000];
inline void dfs(int u) {
  s[u] = p[u], size[u] = 1;
  for (int e = head[u]; e; e = mem[e].next) {
    int to = mem[e].to;
    if (to != f[u]) {
      f[to] = u;
      dfs(to);
      size[u] += size[to];
      s[u] += s[to];
    }
  }
}
int main() {
  n = read();
  for (int i = 1; i < n; i++) {
    u = read(), v = read();
    add(u, v), add(v, u);
  }
  int sumx = 0, sumy = 0;
  for (int i = 1; i <= n; i++) {
    y[i] = read(), x[i] = read();
    sumx += x[i], sumy += y[i];
  }
  for (int i = 1; i <= n; i++) p[i] = y[i] * 1.0 / sumy;
  dfs(1);
  double ans = 0;
  for (int i = 1; i <= n; i++) {
    for (int e = head[i]; e; e = mem[e].next) {
      int to = mem[e].to;
      if (to == f[i])
        ans += (1.0 - s[i]) * x[i] * (n - size[i]) / sumx;
      else
        ans += s[to] * size[to] * x[i] / sumx;
    }
  }
  printf("%.11lf\n", ans);
  return 0;
}
