#include <bits/stdc++.h>
using namespace std;
int lst[100005], to[200005], pre[200005], tot;
double x[100005], y[100005], sumx, sumy, ans;
int sz[100005], n;
inline void add_edge(int u, int v) {
  to[tot] = v;
  pre[tot] = lst[u];
  lst[u] = tot++;
}
void dfs(int u, int fa = -1) {
  sz[u] = 1;
  for (int i = lst[u]; ~i; i = pre[i]) {
    if (to[i] == fa) continue;
    int v = to[i];
    dfs(v, u);
    sz[u] += sz[v];
    x[u] += x[v];
    ans += sz[v] * x[v] * y[u];
  }
  ans += (n - sz[u]) * (sumx - x[u]) * y[u];
}
int main() {
  memset(lst, -1, sizeof(lst));
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    add_edge(--u, --v);
    add_edge(v, u);
  }
  for (int i = 0; i < n; i++) {
    scanf("%lf%lf", x + i, y + i);
    sumx += x[i];
    sumy += y[i];
  }
  dfs(0);
  printf("%.12lf\n", ans / sumx / sumy);
  return 0;
}
