#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e6 + 10;
vector<int> a[MAXN];
long double ans, sumen, sumst, sub[MAXN], st[MAXN], en[MAXN];
int n;
bool mark[MAXN];
void dfs(int v) {
  sub[v] = 1;
  mark[v] = true;
  for (auto u : a[v]) {
    if (mark[u]) continue;
    dfs(u);
    sub[v] += sub[u];
    st[v] += st[u];
    if (en[v]) {
      ans += en[v] * st[u] * sub[u];
    }
  }
  if (en[v]) {
    ans += en[v] * (sumst - st[v]) * (n - sub[v]);
  }
}
int main() {
  cin >> n;
  for (int i = 0, x, y; i < n - 1; i++) {
    cin >> x >> y;
    a[--x].push_back(--y);
    a[y].push_back(x);
  }
  for (int i = 0, x, y; i < n; i++) {
    cin >> x >> y;
    st[i] = x;
    en[i] = y;
    sumst += st[i];
    sumen += en[i];
  }
  dfs(0);
  cout << fixed << setprecision(10) << ans / (sumen * sumst) << endl;
  return 0;
}
