#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100005;
struct EDGE {
  int num, next;
} e[MAXN * 2];
int en = 0, start[MAXN];
inline void Add_edge(int p, int q) {
  en++;
  e[en].num = q;
  e[en].next = start[p];
  start[p] = en;
  en++;
  e[en].num = p;
  e[en].next = start[q];
  start[q] = en;
}
double stp[MAXN], edp[MAXN];
int n;
bool u[MAXN];
int size[MAXN];
double sst[MAXN], pro[MAXN];
void dfs(int p) {
  u[p] = true;
  size[p] = 1;
  sst[p] = stp[p];
  for (int i = start[p]; i != 0; i = e[i].next)
    if (!u[e[i].num]) {
      dfs(e[i].num);
      size[p] += size[e[i].num];
      sst[p] += sst[e[i].num];
      pro[p] += size[e[i].num] * sst[e[i].num];
    }
  pro[p] += (n - size[p]) * (1 - sst[p]);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    int p, q;
    scanf("%d%d", &p, &q);
    Add_edge(p, q);
  }
  double stps = 0, edps = 0;
  for (int i = 1; i <= n; i++) scanf("%lf%lf", &stp[i], &edp[i]);
  for (int i = 1; i <= n; i++) {
    stps += stp[i];
    edps += edp[i];
  }
  for (int i = 1; i <= n; i++) {
    stp[i] /= stps;
    edp[i] /= edps;
  }
  dfs(1);
  double ans = 0;
  for (int i = 1; i <= n; i++) ans += pro[i] * edp[i];
  printf("%.11lf\n", ans);
  return 0;
}
