#include <bits/stdc++.h>
using namespace std;
inline int read() {
  char ch = 0;
  int x = 0, flag = 1;
  while (!isdigit(ch)) {
    ch = getchar();
    if (ch == '-') flag = -1;
  }
  while (isdigit(ch)) {
    x = (x << 3) + (x << 1) + ch - '0';
    ch = getchar();
  }
  return x * flag;
}
struct edge {
  int to, nxt;
} e[220000 * 2];
int num, head[220000];
inline void add(int x, int y) {
  e[++num] = (edge){y, head[x]};
  head[x] = num;
}
int n, sz[220000];
double ans, a[220000], b[220000], dp[220000][2];
void dfs1(int x, int fa) {
  sz[x] = 1;
  for (int i = head[x]; i != -1; i = e[i].nxt) {
    int to = e[i].to;
    if (to == fa) continue;
    dfs1(to, x);
    sz[x] += sz[to];
    dp[x][0] += dp[to][0] + sz[to] * b[to];
  }
}
void dfs2(int x, int fa) {
  if (x != 1)
    dp[x][1] =
        dp[fa][1] + dp[fa][0] - dp[x][0] - sz[x] * b[x] + (n - sz[x]) * b[fa];
  for (int i = head[x]; i != -1; i = e[i].nxt) {
    int to = e[i].to;
    if (to == fa) continue;
    dfs2(to, x);
  }
  ans += a[x] * (dp[x][0] + dp[x][1] + b[x] * n);
}
int main() {
  n = read();
  num = -1;
  memset(head, -1, sizeof(head));
  for (int i = 1; i < n; i++) {
    int x = read(), y = read();
    add(x, y);
    add(y, x);
  }
  int A = 0, B = 0;
  for (int i = 1; i <= n; i++)
    a[i] = read(), b[i] = read(), A += a[i], B += b[i];
  for (int i = 1; i <= n; i++) a[i] /= (double)A, b[i] /= (double)B;
  dfs1(1, 0);
  dfs2(1, 0);
  printf("%.10lf", fabs(n - ans));
  return 0;
}
