#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100000;
const int INF = 0x3f3f3f3f;
template <class T>
void Read(T &x) {
  x = 0;
  char c = getchar();
  bool flag = 0;
  while (c < '0' || '9' < c) {
    if (c == '-') flag = 1;
    c = getchar();
  }
  while ('0' <= c && c <= '9') {
    x = x * 10 + c - '0';
    c = getchar();
  }
  if (flag) x = -x;
}
struct node {
  int v;
  node *nxt;
} * adj[MAXN + 10], Edges[MAXN * 2 + 10], *New = Edges;
inline void addedges(int u, int v) {
  node *p = ++New;
  p->v = v;
  p->nxt = adj[u];
  adj[u] = p;
  p = ++New;
  p->v = u;
  p->nxt = adj[v];
  adj[v] = p;
}
int n;
int bg[MAXN + 10], ed[MAXN + 10];
int totbg, toted;
int fa[MAXN + 10], sz[MAXN + 10];
int sum[MAXN + 10];
void dfs(int x, int f) {
  sz[x] = 1, fa[x] = f, sum[x] = bg[x];
  for (node *p = adj[x]; p != NULL; p = p->nxt) {
    if (p->v == f) continue;
    dfs(p->v, x);
    sz[x] += sz[p->v];
    sum[x] += sum[p->v];
  }
}
int main() {
  int a, b;
  Read(n);
  for (int i = 1; i < n; ++i) Read(a), Read(b), addedges(a, b);
  for (int i = 1; i <= n; ++i)
    Read(bg[i]), Read(ed[i]), totbg += bg[i], toted += ed[i];
  dfs(1, 0);
  double ans = 0, t;
  for (int i = 1; i <= n; ++i) {
    t = 0;
    for (node *p = adj[i]; p != NULL; p = p->nxt)
      if (p->v != fa[i]) t += 1ll * sz[p->v] * sum[p->v] / (double)totbg;
    t += 1ll * (n - sz[i]) * (totbg - sum[i]) / (double)totbg;
    ans += ed[i] / (double)toted * t;
  }
  printf("%0.10f\n", ans);
}
