#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 7, MAXN = 1e5 + 10, MAXM = 2e5 + 10;
int head[MAXN], sz, to[MAXM], nxt[MAXM];
inline void add(int x, int y) {
  nxt[++sz] = head[x], head[x] = sz, to[sz] = y;
  nxt[++sz] = head[y], head[y] = sz, to[sz] = x;
}
int N;
double in[MAXN], out[MAXN], sumin, sumout, ans;
int siz[MAXN], fa[MAXN];
inline void dfs(int x) {
  siz[x] = 1;
  for (int i = head[x]; i; i = nxt[i]) {
    if (to[i] == fa[x]) continue;
    fa[to[i]] = x;
    dfs(to[i]);
    siz[x] += siz[to[i]];
    in[x] += in[to[i]];
  }
}
int main() {
  scanf("%d", &N);
  for (int i = 1; i < N; i++) {
    int ii, jj;
    scanf("%d%d", &ii, &jj);
    add(ii, jj);
  }
  for (int i = 1; i <= N; i++) {
    scanf("%lf%lf", in + i, out + i);
    sumin += in[i];
    sumout += out[i];
  }
  for (int i = 1; i <= N; i++) {
    in[i] /= sumin;
    out[i] /= sumout;
  }
  dfs(1);
  for (int i = 1; i <= N; i++) {
    for (int j = head[i]; j; j = nxt[j]) {
      if (to[j] == fa[i])
        ans += (1 - in[i]) * (N - siz[i]) * out[i];
      else
        ans += in[to[j]] * siz[to[j]] * out[i];
    }
  }
  printf("%.9lf", ans);
  return 0;
}
