#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 9;
int ver[N << 1], nxt[N << 1], h[N], tot, n, siz[N];
double in[N], out[N], ans, sumin, sumout;
inline void add(int u, int v) { ver[++tot] = v, nxt[tot] = h[u], h[u] = tot; }
inline void dfs(int u, int fa) {
  siz[u] = 1;
  for (int i = h[u]; i; i = nxt[i]) {
    int v = ver[i];
    if (v == fa) continue;
    dfs(v, u);
    siz[u] += siz[v];
    in[u] += in[v];
    ans += in[v] * siz[v] * out[u];
  }
  ans += (1 - in[u]) * (n - siz[u]) * out[u];
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    add(u, v), add(v, u);
  }
  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] = in[i] / sumin, out[i] = out[i] / sumout;
  dfs(1, 0);
  printf("%.11lf", ans);
  return 0;
}
