#include <bits/stdc++.h>
int oo[1 + (100000 - 1) * 2], oj[1 + (100000 - 1) * 2];
int link(int o, int j) {
  static int _ = 1;
  oo[_] = o, oj[_] = j;
  return _++;
}
int ae[100000], xx[100000], yy[100000], pp[100000], sz[100000], sx[100000],
    sy[100000];
void dfs(int p, int i) {
  int o;
  pp[i] = p;
  sz[i] = 1, sx[i] = xx[i], sy[i] = yy[i];
  for (o = ae[i]; o; o = oo[o]) {
    int j = oj[o];
    if (j != p) {
      dfs(i, j);
      sz[i] += sz[j], sx[i] += sx[j], sy[i] += sy[j];
    }
  }
}
int main() {
  int n, h, i, j, xsum, ysum;
  long long sum;
  scanf("%d", &n);
  for (h = 0; h < n - 1; h++) {
    scanf("%d%d", &i, &j), i--, j--;
    ae[i] = link(ae[i], j);
    ae[j] = link(ae[j], i);
  }
  xsum = ysum = 0;
  for (i = 0; i < n; i++) {
    scanf("%d%d", &xx[i], &yy[i]);
    xsum += xx[i], ysum += yy[i];
  }
  dfs(-1, 0);
  sum = 0;
  for (i = 0; i < n; i++) {
    int o;
    for (o = ae[i]; o; o = oo[o]) {
      j = oj[o];
      sum += (long long)(j == pp[i] ? n - sz[i] : sz[j]) *
             (j == pp[i] ? xsum - sx[i] : sx[j]) * yy[i];
    }
  }
  printf("%.9f\n", (double)sum / xsum / ysum);
  return 0;
}
