#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> G[100005];
double X[100005], Y[100005];
int sz[100005];
double sx = 0, sy = 0;
double ans = 0;
void dfs(int x, int f) {
  sz[x] = 1;
  for (int i = 0; i < G[x].size(); i++) {
    int u = G[x][i];
    if (u == f) continue;
    dfs(u, x);
    sz[x] += sz[u];
    X[x] += X[u];
    ans += 1.0 * X[u] * sz[u] * Y[x];
  }
  ans += 1.0 * Y[x] * (n - sz[x]) * (sx - X[x]);
}
int main() {
  cin >> n;
  for (int i = 1, a, b; i < n; i++) {
    scanf("%d%d", &a, &b);
    G[a].push_back(b);
    G[b].push_back(a);
  }
  for (int i = 1; i <= n; i++) {
    scanf("%lf%lf", &X[i], &Y[i]);
    sx += X[i];
    sy += Y[i];
  }
  dfs(1, 0);
  printf("%0.9lf\n", 1.0 * ans / sx / sy);
  return 0;
}
