#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 101 * 1001, MOD = 1e9 + 7;
vector<long long> adj[MAXN];
long long sz[MAXN] = {}, ps[MAXN] = {}, st[MAXN], en[MAXN] = {}, n;
long double dp[MAXN], dp2[MAXN] = {}, dp3[MAXN] = {};
void dfs(long long u, long long p) {
  sz[u] = 1;
  ps[u] = en[u];
  for (auto v : adj[u]) {
    if (v == p) continue;
    dfs(v, u);
    sz[u] += sz[v];
    ps[u] += ps[v];
  }
  if (!ps[u]) return;
  for (auto v : adj[u]) {
    if (v == p) continue;
    long double x = ps[v] / (long double)ps[u];
    long double y = dp[v] + 1 + sz[u] - sz[v] - 1;
    dp[u] += x * y;
    if (ps[u] == en[u]) continue;
    x = ps[v] / (long double)(ps[u] - en[u]);
    y = dp[v] + 1 + sz[u] - sz[v] - 1;
    dp3[u] += x * y;
  }
}
void dfs2(long long u, long long p) {
  long double x = 0, k = 0;
  for (auto v : adj[u]) {
    if (v == p) continue;
    k += ps[v];
    x += ps[v] * (n - sz[v] + dp[v]);
  }
  for (auto v : adj[u]) {
    if (v == p) continue;
    if (ps[v] == ps[1]) continue;
    x -= ps[v] * (n - sz[v] + dp[v]);
    x -= (k - ps[v]) * sz[v];
    dp2[v] = x;
    x += ps[v] * (n - sz[v] + dp[v]);
    x += (k - ps[v]) * sz[v];
    dp2[v] /= (long double)(ps[1] - ps[v]);
    dp2[v] += (ps[1] - ps[u]) / (long double)(ps[1] - ps[v]) *
              (dp2[u] + sz[u] - sz[v]);
  }
  for (auto v : adj[u])
    if (v != p) dfs2(v, u);
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long x, y;
  cin >> n;
  for (long long i = 1; i < n; i++)
    cin >> x >> y, adj[x].push_back(y), adj[y].push_back(x);
  long double s = 0;
  for (long long i = 1; i <= n; i++) cin >> st[i] >> en[i], s += st[i];
  dfs(1, 0);
  dfs2(1, 0);
  long double ans = 0;
  for (long long i = 1; i <= n; i++) {
    ans += st[i] / s *
           ((ps[i] - en[i]) / (long double)ps[1] * (dp3[i] + n - sz[i]) +
            (1 - ps[i] / (long double)ps[1]) * (dp2[i] + sz[i]));
  }
  cout << setprecision(10) << ans << endl;
}
