#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
vector<int> a[N];
long long n, sz[N];
long long s[N], e[N], dp_down[N], dp_up[N];
void dfs_down(int v, int p = 0) {
  for (auto u : a[v]) {
    if (u == p) continue;
    dfs_down(u, v);
    dp_down[v] += dp_down[u];
    sz[v] += sz[u];
  }
  sz[v]++;
  dp_down[v] += e[v] * sz[v];
  return;
}
void dfs_up(int v, int p = 0) {
  long long tot = 0;
  for (auto u : a[v]) {
    if (u == p) continue;
    dp_up[u] += dp_up[v];
    tot += dp_down[u];
  }
  for (auto u : a[v]) {
    if (u == p) continue;
    dp_up[u] += tot - dp_down[u];
    dp_up[u] += e[v] * (n - sz[u]);
  }
  for (auto u : a[v]) {
    if (u == p) continue;
    dfs_up(u, v);
  }
  return;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    cin >> u >> v;
    a[u].push_back(v);
    a[v].push_back(u);
  }
  long long st = 0, en = 0;
  for (int i = 1; i <= n; i++) {
    cin >> s[i] >> e[i];
    st += s[i];
    en += e[i];
  }
  dfs_down(1);
  dfs_up(1);
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    long long res = dp_down[i] + dp_up[i] + (n - sz[i]) * e[i];
    res = s[i] * (en * n - res);
    ans += res;
  }
  long double ANS = (long double)ans;
  ANS = (ANS) / ((st * en));
  cout << fixed << setprecision(15) << ANS << '\n';
}
