#include <bits/stdc++.h>
using namespace std;
const int Maxn = 100005;
struct side {
  int a, l;
} e[Maxn * 2];
int x[Maxn], y[Maxn], sy[Maxn], size[Maxn], sumx, sumy;
int n, tot, start[Maxn];
double f[Maxn], g[Maxn], ans;
inline void add(int x, int y) {
  e[++tot].l = start[x];
  e[tot].a = y;
  start[x] = tot;
  e[++tot].l = start[y];
  e[tot].a = x;
  start[y] = tot;
}
void Init() {
  int a, b;
  scanf("%d", &n);
  for (int i = 1; i <= n - 1; ++i) {
    scanf("%d%d", &a, &b);
    add(a, b);
  }
  for (int i = 1; i <= n; ++i) {
    scanf("%d%d", x + i, y + i);
    sumx += x[i];
    sumy += y[i];
  }
}
void dfs(int a, int fa) {
  size[a] = 1;
  sy[a] = y[a];
  for (int i = start[a]; i; i = e[i].l) {
    int b = e[i].a;
    if (b == fa) continue;
    dfs(b, a);
    size[a] += size[b];
    sy[a] += sy[b];
  }
}
void dp(int a, int fa) {
  for (int i = start[a]; i; i = e[i].l) {
    int b = e[i].a;
    if (b == fa || sy[b] == 0) continue;
    dp(b, a);
    f[a] += double(sy[b]) / sy[a] * (size[a] - size[b] + f[b]);
  }
}
void get(int a, int fa) {
  if (sy[a])
    g[a] += double(sy[a]) / sumy *
            (f[a] + (n - size[a]) * (double(sy[a] - y[a]) / sy[a]));
  ans += double(x[a]) / sumx * g[a];
  for (int i = start[a]; i; i = e[i].l) {
    int b = e[i].a;
    if (b == fa) continue;
    if (sumy == sy[b])
      g[b] = 0;
    else {
      g[b] = g[a] - double(sy[b]) / sumy * (n - size[b] + f[b]);
      g[b] = g[b] * double(sumy) / (sumy - sy[b]) -
             size[b] * double(sumy - sy[b] - y[a]) / (sumy - sy[b]);
      g[b] = double(sumy - sy[b]) / sumy * (g[b] + size[b]);
    }
    get(b, a);
  }
}
void Work() {
  dfs(1, 0);
  dp(1, 0);
  get(1, 0);
  printf("%.11lf\n", ans);
}
int main() {
  Init();
  Work();
  return 0;
}
