#include <bits/stdc++.h>
using namespace std;
struct node {
  int next, to;
} e[200005];
double s[100005], t[100005];
int head[100005], fa[100005], siz[100005], g;
int read() {
  int A;
  bool K;
  char C;
  C = A = K = 0;
  while (C < '0' || C > '9') K |= C == '-', C = getchar();
  while (C > '/' && C < ':') A = (A << 3) + (A << 1) + (C ^ 48), C = getchar();
  return (K ? -A : A);
}
inline void add(int u, int v) {
  e[++g].to = v;
  e[g].next = head[u];
  head[u] = g;
}
void dfs(int u) {
  int i, v;
  siz[u] = 1;
  for (i = head[u]; i; i = e[i].next) {
    v = e[i].to;
    if (v == fa[u]) continue;
    fa[v] = u;
    dfs(v);
    siz[u] += siz[v];
    s[u] += s[v];
  }
}
int main() {
  double res = 0.0;
  int n, a, b, i, u, v;
  n = read();
  for (i = 1; i <= (n - 1); i++) {
    a = read(), b = read();
    add(a, b), add(b, a);
  }
  for (i = 1; i <= (n); i++) {
    s[i] = read(), t[i] = read();
    t[0] += t[i];
  }
  dfs(1);
  for (u = 1; u <= (n); u++)
    for (i = head[u]; i; i = e[i].next) {
      v = e[i].to;
      if (v == fa[u])
        res += double(t[u]) / double(t[0]) * double(s[1] - s[u]) /
               double(s[1]) * double(n - siz[u]);
      else
        res += double(s[v]) / double(s[1]) * double(t[u]) / double(t[0]) *
               double(siz[v]);
    }
  cout << fixed << setprecision(10) << res;
  return 0;
}
