#include <bits/stdc++.h>
using namespace std;
int const N = 2e5 + 20;
int n, m, X, Y, par[N], sz[N];
double x[N], y[N], res[N], ans;
vector<int> adj[N];
void dfs1(int v) {
  for (int i = 0; i ^ adj[v].size(); i++) {
    int u = adj[v][i];
    if (u != par[v]) {
      par[u] = v;
      dfs1(u);
      sz[v] += sz[u] + 1;
    }
  }
  res[0] += y[v] * (m - sz[v]);
  return;
}
void dfs2(int v) {
  if (v) res[v] = res[par[v]] - y[v] * (m - sz[v]) + y[par[v]] * (sz[v] + 1);
  for (int i = 0; i ^ adj[v].size(); i++) {
    int u = adj[v][i];
    if (u != par[v]) dfs2(u);
  }
  return;
}
int main() {
  scanf("%d", &n);
  m = n - 1;
  for (int i = 0; i ^ (n - 1); i++) {
    int a, b;
    scanf("%d %d", &a, &b);
    a--, b--;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  for (int i = 0; i ^ n; i++) {
    scanf("%lf %lf", x + i, y + i);
    X += x[i];
    Y += y[i];
  }
  for (int i = 0; i ^ n; i++) {
    x[i] /= X;
    y[i] /= Y;
  }
  dfs1(0);
  dfs2(0);
  for (int i = 0; i ^ n; i++) ans += x[i] * res[i];
  printf("%.15lf", ans);
  return 0;
}
