#include <bits/stdc++.h>
using namespace std;
long long n, tot, h[100005], fa[100005], sz[100005];
double ans, sumin, sumout, in[100005], out[100005];
struct edge {
  long long u, v;
} e[100005 << 1];
template <typename T>
inline void read(T &x) {
  T f = 0, c = getchar();
  for (; c < '0' || '9' < c; c = getchar())
    if (c == '-') f = 1;
  for (x = 0; '0' <= c && c <= '9'; c = getchar()) x = x * 10 + c - '0';
  if (f) x = -x;
}
inline void add(long long u, long long v) {
  e[++tot] = (edge){h[u], v}, h[u] = tot;
}
void dfs(long long x, long long f) {
  fa[x] = f, sz[x] = 1;
  for (register long long i = h[x]; i; i = e[i].u)
    if (e[i].v ^ f) dfs(e[i].v, x), sz[x] += sz[e[i].v], in[x] += in[e[i].v];
}
signed main() {
  read(n);
  for (register long long i = 1, x, y; i < n; ++i)
    read(x), read(y), add(x, y), add(y, x);
  for (register long long i = 1; i <= n; ++i)
    read(in[i]), read(out[i]), sumin += in[i], sumout += out[i];
  for (register long long i = 1; i <= n; ++i) in[i] /= sumin, out[i] /= sumout;
  dfs(1, 0);
  for (register long long i = 1; i <= n; ++i)
    for (register long long j = h[i]; j; j = e[j].u)
      if (fa[i] ^ e[j].v)
        ans += in[e[j].v] * sz[e[j].v] * out[i];
      else
        ans += (1 - in[i]) * (n - sz[i]) * out[i];
  printf("%.20lf", ans);
  return 0;
}
