#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
const int M = 3e5 + 5;
int n, u, v;
int E, ot[M], ne[M], g[N];
int siz[N];
double sum[N], ans;
pair<double, double> P[N];
void add(int u, int v) {
  ot[++E] = v;
  ne[E] = g[u];
  g[u] = E;
}
void init() {
  int i;
  scanf("%d", &n);
  for (i = 1; i < n; ++i) {
    scanf("%d%d", &u, &v);
    add(u, v), add(v, u);
  }
  pair<double, double> tot = make_pair(0, 0);
  for (i = 1; i <= n; ++i) {
    scanf("%lf%lf", &P[i].first, &P[i].second);
    tot.first += P[i].first, tot.second += P[i].second;
  }
  for (i = 1; i <= n; ++i) P[i].first /= tot.first, P[i].second /= tot.second;
}
void dfs(int x, int fath) {
  int p, to;
  siz[x] = 1, sum[x] = P[x].first;
  double ins = 0;
  for (p = g[x]; p; p = ne[p]) {
    to = ot[p];
    if (to == fath) continue;
    dfs(to, x);
    siz[x] += siz[to];
    sum[x] += sum[to];
    ins += sum[to] * siz[to];
  }
  ins += (1 - sum[x]) * (n - siz[x]);
  ans += ins * P[x].second;
}
int main() {
  init();
  dfs(1, 0);
  printf("%.12lf\n", ans);
  return 0;
}
