#include <bits/stdc++.h>
using namespace std;
int Get() {
  char c;
  while (c = getchar(), c < '0' || c > '9')
    ;
  int X = c - 48;
  while (c = getchar(), c >= '0' && c <= '9') X = X * 10 + c - 48;
  return X;
}
vector<int> G[100000];
double P[100000], Q[100000], Sum[100000];
int Parent[100000], Size[100000];
void DFS(int X) {
  Sum[X] = P[X];
  Size[X] = 1;
  for (int i = 0; i < G[X].size(); i++)
    if (G[X][i] != Parent[X]) {
      Parent[G[X][i]] = X;
      DFS(G[X][i]);
      Sum[X] += Sum[G[X][i]];
      Size[X] += Size[G[X][i]];
    }
}
int main() {
  int N = Get();
  for (int i = 1; i < N; i++) {
    int X = Get() - 1, Y = Get() - 1;
    G[X].push_back(Y);
    G[Y].push_back(X);
  }
  for (int i = 0; i < N; i++) {
    P[i] = Get();
    Q[i] = Get();
  }
  double Sum_P = 0, Sum_Q = 0;
  for (int i = 0; i < N; i++) Sum_P += P[i];
  for (int i = 0; i < N; i++) P[i] /= Sum_P;
  for (int i = 0; i < N; i++) Sum_Q += Q[i];
  for (int i = 0; i < N; i++) Q[i] /= Sum_Q;
  Parent[0] = -1;
  DFS(0);
  double Ans = 0;
  for (int i = 0; i < N; i++) {
    double Temp = (1 - Sum[i]) * (N - Size[i]);
    for (int j = 0; j < G[i].size(); j++)
      if (G[i][j] != Parent[i]) Temp += Sum[G[i][j]] * Size[G[i][j]];
    Ans += Temp * Q[i];
  }
  printf("%0.10lf\n", Ans);
  return 0;
}
