#include <bits/stdc++.h>
using namespace std;
const int N = 1000 * 100 + 10;
int n;
vector<int> v[N];
long double sum[N], sumx, sumy, x[N], y[N];
int sub[N];
bool check[N];
long double ans;
void DFS(int r) {
  check[r] = true;
  sum[r] = x[r];
  for (int i = 0; i < (int)v[r].size(); i++)
    if (!check[v[r][i]]) {
      DFS(v[r][i]);
      sub[r] += sub[v[r][i]] + 1;
      sum[r] += sum[v[r][i]];
      ans += (sub[v[r][i]] + 1) * (sum[v[r][i]] / sumx) * (y[r] / sumy);
    }
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n - 1; i++) {
    int xx, yy;
    scanf("%d%d", &xx, &yy);
    xx--;
    yy--;
    v[xx].push_back(yy);
    v[yy].push_back(xx);
  }
  for (int i = 0; i < n; i++) {
    scanf("%Lf%Lf", &x[i], &y[i]);
    sumx += x[i];
    sumy += y[i];
  }
  DFS(0);
  for (int i = 0; i < n; i++) {
    ans += (n - 1 - sub[i]) * (sumx - sum[i]) / sumx * (y[i] / sumy);
  }
  printf("%.20Lf\n", ans);
  return 0;
}
