#include <bits/stdc++.h>
using namespace std;
const int N = 100050;
long long dp[N], dw[N], up[N];
int sz[N], sum_y[N], x[N], y[N], n, X, Y;
vector<int> E[N];
void DFS(int u, int p) {
  sz[u] = 1;
  sum_y[u] = y[u];
  for (int v : E[u])
    if (v != p) {
      DFS(v, u);
      sz[u] += sz[v];
      sum_y[u] += sum_y[v];
    }
  for (int v : E[u])
    if (v != p) {
      dw[u] += dw[v] + (long long)(sz[u] - sz[v]) * sum_y[v];
    }
}
long long Solve(int u, int p) {
  long long all = p != 0 ? up[u] - (long long)(n - sz[u]) * (Y - sum_y[u]) : 0;
  for (int v : E[u])
    if (v != p) {
      all += dw[v] - (long long)sz[v] * sum_y[v];
    }
  dp[u] = all + (long long)n * (Y - y[u]);
  long long ans = (long long)dp[u] * x[u];
  for (int v : E[u])
    if (v != p) {
      up[v] = all - (dw[v] - (long long)sz[v] * sum_y[v]);
      up[v] += (long long)(n - sz[v]) * (Y - sum_y[v] - y[u]);
      ans += Solve(v, u);
    }
  return ans;
}
int main() {
  scanf("%i", &n);
  for (int i = 1, u, v; i < n; i++)
    scanf("%i %i", &u, &v), E[u].push_back(v), E[v].push_back(u);
  int sum_x = 0, sum_y = 0;
  for (int i = 1; i <= n; i++)
    scanf("%i %i", &x[i], &y[i]), X += x[i], Y += y[i];
  DFS(1, 0);
  printf("%.12f\n", (double)Solve(1, 0) / X / Y);
  return 0;
}
