#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e6 + 100;
vector<int> ver[MAXN];
int sz[MAXN], sumst, sumfn;
int st[MAXN], fn[MAXN];
long double ans = 0;
void dfs(int v, int par, int n) {
  for (auto u : ver[v])
    if (u != par) {
      dfs(u, v, n);
      ans += sz[u] * (1.00 * st[u] / sumst) * (1.00 * fn[v] / sumfn);
      sz[v] += sz[u];
      st[v] += st[u];
    }
  sz[v]++;
  ans +=
      (n - sz[v]) * (1.00 * (sumst - st[v]) / sumst) * (1.00 * fn[v] / sumfn);
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  for (int i = 1; i < n; i++) {
    int x, y;
    cin >> x >> y;
    ver[x].push_back(y);
    ver[y].push_back(x);
  }
  for (int i = 1; i <= n; i++)
    cin >> st[i] >> fn[i], sumfn += fn[i], sumst += st[i];
  dfs(1, 0, n);
  cout << fixed << setprecision(20);
  cout << ans;
}
