#include <bits/stdc++.h>
using namespace std;
int n, tot;
int sz[200005], point[200005], nxt[200005], head[200005];
double ans, ps[200005], pt[200005], f[200005], tots, tott;
void addedge(int x, int y) {
  point[++tot] = y, nxt[tot] = head[x], head[x] = tot;
  point[++tot] = x, nxt[tot] = head[y], head[y] = tot;
}
void dfs(int x, int fa) {
  f[x] = ps[x], sz[x] = 1;
  for (int i = head[x]; i; i = nxt[i]) {
    int y = point[i];
    if (y == fa) continue;
    dfs(y, x);
    f[x] += f[y], sz[x] += sz[y];
    ans += pt[x] * f[y] * sz[y];
  }
  ans += pt[x] * (n - sz[x]) * (1 - f[x]);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n - 1; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    addedge(x, y);
  }
  for (int i = 1; i <= n; i++)
    scanf("%lf%lf", &ps[i], &pt[i]), tots += ps[i], tott += pt[i];
  for (int i = 1; i <= n; i++) ps[i] /= tots, pt[i] /= tott;
  dfs(1, 0);
  printf("%.11lf\n", ans);
  return 0;
}
