#include <bits/stdc++.h>
namespace IO {
const int IN_LEN = 1 << 18 | 1;
static char buf[IN_LEN], *s, *t;
inline int Getchar(void) {
  return s == t && (t = (s = buf) + fread(buf, 1, IN_LEN, stdin)),
         s == t ? -1 : *s++;
}
template <class T>
inline void read(T& x) {
  static int c, f;
  for (c = Getchar(), f = 0; c < '0' || c > '9'; c = Getchar())
    if (c == '-') f = 1;
  for (x = 0; c <= '9' && c >= '0'; c = Getchar()) x = x * 10 + c - 48;
  x = f ? -x : x;
}
}  // namespace IO
using IO::read;
const int MAXN = 1e5 + 1;
int n, head[MAXN], cnt, fa[MAXN], sums, sumt, siz[MAXN];
double s[MAXN], t[MAXN], ans;
struct EE {
  int next, to;
} edge[MAXN << 1];
inline void addedge(int f, int t) {
  edge[++cnt] = (EE){head[f], t};
  head[f] = cnt;
}
void dfs(int u) {
  siz[u] = 1;
  for (int i = head[u]; i; i = edge[i].next)
    if (edge[i].to != fa[u]) {
      fa[edge[i].to] = u;
      dfs(edge[i].to);
      siz[u] += siz[edge[i].to];
      s[u] += s[edge[i].to];
    }
}
int main(void) {
  read(n);
  for (int i = 1, u, v; i < n; ++i) {
    read(u), read(v);
    addedge(u, v), addedge(v, u);
  }
  for (int i = 1; i <= n; ++i) {
    read(s[i]), read(t[i]);
    sums += s[i], sumt += t[i];
  }
  for (int i = 1; i <= n; ++i) s[i] /= (double)sums, t[i] /= (double)sumt;
  dfs(1);
  for (int i = 1; i <= n; ++i) {
    for (int j = head[i]; j; j = edge[j].next) {
      int& v = edge[j].to;
      if (v == fa[i])
        ans += (1 - s[i]) * (n - siz[i]) * t[i];
      else
        ans += s[v] * siz[v] * t[i];
    }
  }
  printf("%.12f", ans);
  return 0;
}
