#include <bits/stdc++.h>
using namespace std;
struct line {
  int v, next;
} e[200005];
int t, b[100005], n, x, y, sz[100005], X[100005], Y[100005], f[100005];
double s[100005], p[100005];
inline void build(int x, int y) { e[++t].v = y, e[t].next = b[x], b[x] = t; }
void dfs(int u) {
  s[u] = p[u], sz[u] = 1;
  for (int o = b[u]; o != -1; o = e[o].next) {
    int v = e[o].v;
    if (v == f[u]) continue;
    f[v] = u;
    dfs(v);
    s[u] += s[v], sz[u] += sz[v];
  }
}
int main() {
  scanf("%d", &n);
  memset(b, -1, sizeof b);
  t = -1;
  for (int i = 1; i < n; i++) {
    scanf("%d%d", &x, &y);
    build(x, y), build(y, x);
  }
  int sumX = 0, sumY = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%d%d", &Y[i], &X[i]);
    sumX += X[i], sumY += Y[i];
  }
  for (int i = 1; i <= n; i++) p[i] = Y[i] * 1.0 / sumY;
  dfs(1);
  double ans = 0;
  for (int i = 1; i <= n; i++) {
    for (int o = b[i]; o != -1; o = e[o].next) {
      int v = e[o].v;
      if (v == f[i])
        ans += (1.0 - s[i]) * (n - sz[i]) * X[i] / sumX;
      else
        ans += s[v] * sz[v] * X[i] / sumX;
    }
  }
  printf("%.11lf\n", ans);
  return 0;
}
