#include <bits/stdc++.h>
using namespace std;
const int Max_N(100050);
namespace io {
const int SIZE = (1 << 21) + 1;
char ibuf[SIZE], *iS, *iT, obuf[SIZE], *oS = obuf, *oT = oS + SIZE - 1, c,
                                       qu[55];
int f, qr;
inline void flush() {
  fwrite(obuf, 1, oS - obuf, stdout);
  oS = obuf;
}
inline void putc(char x) {
  *oS++ = x;
  if (oS == oT) flush();
}
template <class I>
inline void gi(I &x) {
  for (f = 1, c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin),
                              (iS == iT ? EOF : *iS++))
                            : *iS++);
       c < '0' || c > '9';
       c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin),
                       (iS == iT ? EOF : *iS++))
                     : *iS++))
    if (c == '-') f = -1;
  for (x = 0; c <= '9' && c >= '0';
       c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin),
                       (iS == iT ? EOF : *iS++))
                     : *iS++))
    x = x * 10 + (c & 15);
  x *= f;
}
template <class I>
inline void print(I x) {
  if (!x) putc('0');
  if (x < 0) putc('-'), x = -x;
  while (x) qu[++qr] = x % 10 + '0', x /= 10;
  while (qr) putc(qu[qr--]);
}
struct Flusher_ {
  ~Flusher_() { flush(); }
} io_flusher_;
}  // namespace io
using io::gi;
using io::print;
using io::putc;
int N, Head[Max_N], Total, To[Max_N << 1], Next[Max_N << 1], X[Max_N], Y[Max_N],
    Size[Max_N];
long long int Sum[Max_N];
double Ans;
inline void Add_Edge(int s, int t) {
  ++Total, To[Total] = t, Next[Total] = Head[s], Head[s] = Total;
}
void dfs1(int u, int fa) {
  for (int i = Head[u], v; i; i = Next[i])
    if ((v = To[i]) != fa) dfs1(v, u), Size[u] += Size[v] + 1;
  Sum[1] += Y[u] * 1LL * Size[u];
}
void dfs2(int u, int fa) {
  for (int i = Head[u], v; i; i = Next[i])
    if ((v = To[i]) != fa) {
      Sum[v] = Sum[u], Sum[v] += Y[v] * 1LL * (N - 1LL - Size[v]),
      Sum[v] -= Y[u] * 1LL * (Size[v] + 1LL);
      dfs2(v, u);
    }
  Ans += (X[u] * 1.0 / X[0]) * ((N - 1LL) * 1LL * Y[0] - Sum[u]) * 1.0 / Y[0];
}
int main() {
  gi(N);
  for (int i = 1, u, v; i != N; ++i)
    gi(u), gi(v), Add_Edge(u, v), Add_Edge(v, u);
  for (int i = 1; i <= N; ++i) gi(X[i]), gi(Y[i]), X[0] += X[i], Y[0] += Y[i];
  dfs1(1, -1), dfs2(1, -1);
  printf("%.10lf", Ans);
  return 0;
}
