#include <bits/stdc++.h>
using namespace std;
vector<int> g[100100];
int a[100100], b[100100], s[100100];
int n, sa, sb;
double ans;
void dfs(int v, int p) {
  s[v] = 1;
  for (int i = 0; i < g[v].size(); i++) {
    int u = g[v][i];
    if (u == p) continue;
    dfs(u, v);
    s[v] += s[u];
    a[v] += a[u];
    ans += 1.0 * b[v] * s[u] * a[u];
  }
  ans += 1.0 * b[v] * (n - s[v]) * (sa - a[v]);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    g[u].push_back(v);
    g[v].push_back(u);
  }
  for (int i = 1; i <= n; i++) scanf("%d%d", a + i, b + i);
  for (int i = 1; i <= n; i++) {
    sa += a[i];
    sb += b[i];
  }
  dfs(1, 0);
  printf("%.12lf\n", ans / sa / sb);
  return 0;
}
