#include <bits/stdc++.h>
using namespace std;
const int mn = 110000;
long long X, Y, ans;
vector<int> e[mn];
int n, x[mn], y[mn], sx[mn], s[mn];
void dfs(int r, int fa) {
  s[r] = 1, sx[r] = x[r];
  for (int p = 0, i; p < e[r].size(); ++p) {
    i = e[r][p];
    if (i == fa) continue;
    dfs(i, r);
    ans += (long long)sx[i] * s[i] * y[r];
    s[r] += s[i], sx[r] += sx[i];
  }
  ans += (long long)(X - sx[r]) * (n - s[r]) * y[r];
}
int main() {
  int i, j, k;
  scanf("%d", &n);
  for (i = 1; i <= n - 1; ++i) {
    scanf("%d%d", &j, &k);
    e[j].push_back(k), e[k].push_back(j);
  }
  for (i = 1; i <= n; ++i) {
    scanf("%d%d", x + i, y + i);
    X += x[i], Y += y[i];
  }
  dfs(1, 0);
  printf("%.10lf\n", (double)ans / (double)X / double(Y));
  return 0;
}
