#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5;
long long sz[maxn + 10], esum, ssum, start[maxn + 10], endd[maxn + 10],
    dp[maxn + 10];
double rez, sol;
int n;
vector<int> vect[maxn + 10];
void calc2(int x, int prv) {
  sz[x] = 1;
  for (int i = 0; i < vect[x].size(); i++) {
    int id = vect[x][i];
    if (id == prv) continue;
    calc2(id, x);
    sz[x] += sz[id];
  }
}
void calc(int x, int prv, int sum) {
  dp[x] = (double)sum * endd[x];
  for (int i = 0; i < vect[x].size(); i++) {
    int id = vect[x][i];
    if (id == prv) continue;
    calc(id, x, sum + 1 + sz[x] - 1 - sz[id]);
    dp[x] += dp[id];
  }
}
void go(int x, int prv) {
  sol += rez * start[x];
  for (int i = 0; i < vect[x].size(); i++) {
    int id = vect[x][i];
    if (id == prv) continue;
    rez += endd[x] * (sz[id]);
    rez -= endd[id] * (sz[1] - sz[id]);
    go(id, x);
    rez -= endd[x] * (sz[id]);
    rez += endd[id] * (sz[1] - sz[id]);
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    int u, v;
    scanf("%d %d", &u, &v);
    vect[u].push_back(v);
    vect[v].push_back(u);
  }
  for (int i = 1; i <= n; i++) {
    scanf("%lld %lld", &start[i], &endd[i]);
    ssum += start[i];
    esum += endd[i];
  }
  calc2(1, 0);
  calc(1, 0, 0);
  rez = dp[1];
  go(1, 0);
  printf("%.9lf\n", sol / ((double)esum * ssum));
  return 0;
}
