#include <bits/stdc++.h>
using namespace std;
struct note {
  int to, next;
} edge[100010 << 1];
int tot, head[100010];
int i, j, n, m;
int u, v, siz[100010], fa[100010];
int a[100010], b[100010], sa, sb;
double A[100010], B[100010], ans;
void lb(int x, int y) {
  edge[++tot].to = y;
  edge[tot].next = head[x];
  head[x] = tot;
}
void dg(int x) {
  int i;
  siz[x] = 1;
  for (i = head[x]; i; i = edge[i].next)
    if (edge[i].to ^ fa[x]) {
      fa[edge[i].to] = x;
      dg(edge[i].to);
      siz[x] += siz[edge[i].to];
      A[x] += A[edge[i].to];
      ans += A[edge[i].to] * siz[edge[i].to] * B[x];
    }
  ans += (1 - A[x]) * (n - siz[x]) * B[x];
}
int main() {
  scanf("%d", &n);
  for (i = 1; i <= n - 1; i++) {
    scanf("%d%d", &u, &v);
    lb(u, v);
    lb(v, u);
  }
  for (i = 1; i <= n; i++) {
    scanf("%d%d", &a[i], &b[i]);
    sa += a[i], sb += b[i];
  }
  for (i = 1; i <= n; i++) A[i] = 1.0 * a[i] / sa, B[i] = 1.0 * b[i] / sb;
  ans = 0;
  dg(1);
  printf("%.12lf\n", ans);
  return 0;
}
