#include <bits/stdc++.h>
using namespace std;
const int N = 200005, M = 400005;
int n, tot = 0, Next[M], to[M], head[M], sz[N], x[N], y[N], X = 0, Y = 0;
double f[N], re = 0, now = 0;
inline void add(int x, int y) {
  Next[++tot] = head[x];
  to[tot] = y;
  head[x] = tot;
}
inline void dfs(int x, int fa) {
  int i;
  sz[x] = 1;
  for (i = head[x]; i; i = Next[i])
    if (to[i] != fa) {
      dfs(to[i], x);
      sz[x] += sz[to[i]];
    }
  return;
}
inline void dfs1(int x, int fa) {
  int i;
  now += f[x] * y[x];
  for (i = head[x]; i; i = Next[i])
    if (to[i] != fa) {
      f[to[i]] = f[x] + (sz[x] - sz[to[i]] - 1) + 1;
      dfs1(to[i], x);
    }
  return;
}
inline void dfs2(int u, int fa) {
  int i;
  re += 1.0 * now / Y * x[u];
  for (i = head[u]; i; i = Next[i])
    if (to[i] != fa) {
      now -= f[to[i]] * y[to[i]];
      now += sz[to[i]] * y[u];
      dfs2(to[i], u);
      now += f[to[i]] * y[to[i]];
      now -= sz[to[i]] * y[u];
    }
  return;
}
int main() {
  int i, xx, yy;
  scanf("%d", &n);
  for (i = 1; i < n; i++) {
    scanf("%d%d", &xx, &yy);
    add(xx, yy);
    add(yy, xx);
  }
  for (i = 1; i <= n; i++) scanf("%d%d", &x[i], &y[i]), X += x[i], Y += y[i];
  dfs(1, 0);
  dfs1(1, 0);
  dfs2(1, 0);
  printf("%.10lf\n", (double)re / X);
}
