#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 10;
long long n, x[MAXN], y[MAXN], Y, X;
vector<int> adj[MAXN];
long long sz[MAXN], sx[MAXN];
long long answer;
void dfs(int v, int par = 0) {
  sz[v]++;
  sx[v] += x[v];
  for (auto i : adj[v])
    if (i != par) {
      dfs(i, v);
      sz[v] += sz[i];
      sx[v] += sx[i];
      answer += sz[i] * sx[i] * y[v];
    }
  answer += (n - sz[v]) * (X - sx[v]) * y[v];
  return;
}
int main() {
  ios::sync_with_stdio(0);
  cin >> n;
  for (int i = 1; i < n; i++) {
    int u, v;
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  for (int i = 1; i <= n; i++) {
    cin >> x[i] >> y[i];
    X += x[i];
    Y += y[i];
  }
  dfs(1);
  cout << fixed << setprecision(12) << (long double)answer / (X * Y) << endl;
  return 0;
}
