#include <bits/stdc++.h>
using namespace std;
const int M = 1e5 + 5;
struct edge {
  int v, to;
} E[M << 1];
int tot, head[M];
void Link(int u, int v) {
  E[++tot] = (edge){v, head[u]};
  head[u] = tot;
}
int n, S[M], T[M], Ssum, Tsum;
int fa[M], sz[M], pro[M];
void dfs(int u) {
  sz[u] = 1;
  pro[u] = S[u];
  for (int i = head[u]; i != 0; i = E[i].to) {
    int v = E[i].v;
    if (v == fa[u]) continue;
    fa[v] = u;
    dfs(v);
    sz[u] += sz[v];
    pro[u] += pro[v];
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    Link(u, v);
    Link(v, u);
  }
  for (int i = 1; i <= n; i++)
    scanf("%d%d", &S[i], &T[i]), Ssum += S[i], Tsum += T[i];
  dfs(1);
  long long ans = 0;
  for (int u = 1; u <= n; u++)
    for (int i = head[u]; i != 0; i = E[i].to) {
      int v = E[i].v, Sz, Pro;
      if (v == fa[u])
        Sz = n - sz[u], Pro = Ssum - pro[u];
      else
        Sz = sz[v], Pro = pro[v];
      ans += 1ll * Sz * Pro * T[u];
    }
  printf("%.12lf", ans * 1.0 / Ssum / Tsum);
  return 0;
}
