#include <bits/stdc++.h>
using namespace std;
const int _ = 100001;
double px[_], py[_], alx, aly;
int to[_ << 1], nxt[_ << 1], head[_], cnt;
inline void add(register int a, register int b) {
  to[++cnt] = b, nxt[cnt] = head[a], head[a] = cnt;
}
int Size[_], n;
double ans;
double dfs(int x, int fa) {
  register double as = 0, ds;
  Size[x] = 1;
  for (register int i = head[x]; i; i = nxt[i]) {
    if (to[i] == fa) continue;
    ds = dfs(to[i], x);
    Size[x] += Size[to[i]], as += ds;
    ans += (Size[to[i]]) * (ds / alx) * (py[x] / aly);
  }
  as += px[x];
  ans += ((alx - as) / alx) * (n - Size[x]) * (py[x] / aly);
  return as;
}
int main() {
  scanf("%d", &n);
  register int i, a, b;
  for (i = 1; i < n; ++i) {
    scanf("%d%d", &a, &b);
    add(a, b), add(b, a);
  }
  for (i = 1; i <= n; ++i) {
    scanf("%lf%lf", &px[i], &py[i]);
    alx += px[i], aly += py[i];
  }
  dfs(1, 0);
  printf("%.10lf", ans);
}
