#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 4;
vector<int> e[N];
int n, siz[N];
long long ans;
int sn = 0, sx = 0;
int en[N], ex[N];
void dfs(int u, int fa) {
  siz[u] = 1;
  for (auto v : e[u]) {
    if (v == fa) continue;
    dfs(v, u);
    siz[u] += siz[v];
    en[u] += en[v];
    ans += 1ll * ex[u] * en[v] * siz[v];
  }
  ans += 1ll * ex[u] * (sn - en[u]) * (n - siz[u]);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    int u, v;
    scanf("%d %d", &u, &v);
    e[u].push_back(v);
    e[v].push_back(u);
  }
  for (int i = 1; i <= n; i++)
    scanf("%d %d", &en[i], &ex[i]), sn += en[i], sx += ex[i];
  dfs(1, 0);
  printf("%.10f\n", (double)(ans / (1.0 * sx * sn)));
  return 0;
}
