#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
int n, x[N], y[N];
double p[N], q[N], sub[N];
double need[N], up[N];
vector<int> g[N];
int sz[N];
int Sx, Sy;
double ans;
void dfs(int u, int pre) {
  sz[u] = 1;
  sub[u] = 0;
  for (int i = 0; i < g[u].size(); ++i) {
    int v = g[u][i];
    if (v == pre) continue;
    dfs(v, u);
    sz[u] += sz[v];
    sub[u] += sub[v];
  }
  sub[u] += q[u] * sz[u];
}
void dfs1(int u, int pre) {
  for (int i = 0; i < g[u].size(); ++i) {
    int v = g[u][i];
    if (v == pre) continue;
    up[v] = up[u] + q[u] * (n - sz[v]) + (sub[u] - q[u] * sz[u] - sub[v]);
    double tot = up[v] + sub[v] - q[v] * sz[v] + q[v] * n;
    tot = n - tot;
    ans += p[v] * tot;
    dfs1(v, u);
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i < n; ++i) {
    int u, v;
    scanf("%d%d", &u, &v);
    g[u].push_back(v);
    g[v].push_back(u);
  }
  for (int i = 1; i <= n; ++i) {
    scanf("%d%d", &x[i], &y[i]);
  }
  Sx = accumulate(x + 1, x + n + 1, 0), Sy = accumulate(y + 1, y + n + 1, 0);
  for (int i = 1; i <= n; ++i) {
    p[i] = x[i] / (double)Sx;
    q[i] = y[i] / (double)Sy;
  }
  dfs(1, 0);
  ans += p[1] * (n - sub[1]);
  dfs1(1, 0);
  cout << fixed << setprecision(10) << ans << '\n';
  return 0;
}
