#include <bits/stdc++.h>
using namespace std;
inline int in() {
  int x;
  scanf("%d", &x);
  return x;
}
const int INF = 1e9 + 10;
const long long LINF = 1000ll * 1000 * 1000 * 1000 * 1000 * 1000 + 100;
const int MN = 2e5 + 10;
double dp[MN], St[MN], Fn[MN];
double Sum1, Sum2;
int sz[MN];
vector<int> adj[MN];
int n;
void input() {
  n = in();
  for (int i = 0; i < n - 1; ++i) {
    int a, b;
    a = in(), b = in();
    --a, --b;
    adj[a].push_back(b), adj[b].push_back(a);
  }
  for (int i = 0; i < n; ++i) {
    scanf("%lf %lf", &St[i], &Fn[i]);
    Sum1 += St[i], Sum2 += Fn[i];
  }
}
void dfs_up(int s, int pr) {
  sz[s] = 1;
  for (int i = 0; i < ((int)(adj[s]).size()); ++i) {
    int v = adj[s][i];
    if (v == pr) continue;
    dfs_up(v, s);
    sz[s] += sz[v];
  }
  dp[0] += (Fn[s] / Sum2) * (n - sz[s]);
}
void dfs_down(int s, int pr) {
  if (pr != -1)
    dp[s] = dp[pr] + (Fn[pr] / Sum2) * sz[s] - (Fn[s] / Sum2) * (n - sz[s]);
  for (int i = 0; i < ((int)(adj[s]).size()); ++i) {
    int v = adj[s][i];
    if (v == pr) continue;
    dfs_down(v, s);
  }
}
int main() {
  input();
  dfs_up(0, -1);
  dfs_down(0, -1);
  double ans = 0;
  for (int i = 0; i < n; ++i) ans += (St[i] / Sum1) * dp[i];
  double t = ans;
  printf("%.12lf\n", t);
  return 0;
}
