#include <bits/stdc++.h>
using namespace std;
template <typename T>
void chkmin(T &a, T b) {
  a = min(a, b);
}
template <typename T>
void chkmax(T &a, T b) {
  a = max(a, b);
}
inline int fread(void) {
  int ret = 0, op = 1;
  char ch = getchar();
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') op = -1;
  for (; isdigit(ch); ch = getchar()) ret = (ret << 1) + (ret << 3) - '0' + ch;
  return ret * op;
}
const int MAXN = 1e5 + 10;
const int MAXM = +10;
int head[MAXN], nxt[MAXN << 1], to[MAXN << 1], ind;
inline void add_edge(int u, int v) {
  nxt[++ind] = head[u];
  head[u] = ind;
  to[ind] = v;
}
inline void add(int u, int v) {
  add_edge(u, v);
  add_edge(v, u);
}
int n, in[MAXN], out[MAXN], totIn, totOut;
double P[MAXN], Q[MAXN];
inline void init(void) {
  n = fread();
  int u, v;
  for (int i = 1; i < n; ++i) {
    u = fread(), v = fread();
    add(u, v);
  }
  for (int i = 1; i <= n; ++i) {
    in[i] = fread();
    out[i] = fread();
    totIn += in[i];
    totOut += out[i];
  }
  for (int i = 1; i <= n; ++i)
    P[i] = (double)in[i] / totIn, Q[i] = (double)out[i] / totOut;
}
int siz[MAXN];
double f[MAXN], ans;
void dfs(int u, int fa) {
  siz[u] = 1;
  for (int i = head[u]; i; i = nxt[i]) {
    int v = to[i];
    if (v == fa) continue;
    dfs(v, u);
    siz[u] += siz[v];
  }
  f[1] += Q[u] * siz[u];
}
void TreeDP(int u, int fa) {
  for (int i = head[u]; i; i = nxt[i]) {
    int v = to[i];
    if (v == fa) continue;
    f[v] = f[u] - siz[v] * Q[u] + (n - siz[v]) * Q[v];
    TreeDP(v, u);
  }
}
inline void work(void) {
  ans = n;
  dfs(1, 0);
  TreeDP(1, 0);
  for (int i = 1; i <= n; ++i) {
    ans -= f[i] * P[i];
  }
  printf("%.12lf", ans);
}
int main() {
  init();
  work();
  return 0;
}
