#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline void read(T &x) {
  x = 0;
  int fu = 1;
  char c = getchar();
  while (c > 57 || c < 48) {
    if (c == 45) fu = -1;
    c = getchar();
  }
  while (c <= 57 && c >= 48) {
    x = (x << 3) + (x << 1) + c - 48;
    c = getchar();
  }
  x *= fu;
}
template <typename T>
inline void fprint(T x) {
  if (x < 0) putchar(45), x = -x;
  if (x > 9) fprint(x / 10);
  putchar(x % 10 + 48);
}
template <typename T>
inline void fprint(T x, char ch) {
  fprint(x);
  putchar(ch);
}
int n, sz[100010], fa[100010];
int head[100010], cnt, nxt[200010], e[200010];
inline void add(int u, int v) {
  nxt[++cnt] = head[u];
  head[u] = cnt;
  e[cnt] = v;
}
double ans = 0, pin[100010], pout[100010], totin, totout;
void dfs(int x) {
  sz[x] = 1;
  for (register int i = head[x]; i; i = nxt[i]) {
    if (fa[x] == e[i]) continue;
    fa[e[i]] = x;
    dfs(e[i]);
    sz[x] += sz[e[i]];
    pin[x] += pin[e[i]];
    ans = ans + pin[e[i]] * sz[e[i]] * pout[x];
  }
  ans = ans + (1 - pin[x]) * (n - sz[x]) * pout[x];
}
int main() {
  read(n);
  for (register int i = 1; i < n; i++) {
    int u, v;
    read(u);
    read(v);
    add(u, v);
    add(v, u);
  }
  for (register int i = 1; i <= n; i++) {
    scanf("%lf%lf", &pin[i], &pout[i]);
    totin += pin[i];
    totout += pout[i];
  }
  for (register int i = 1; i <= n; i++) {
    pin[i] /= totin;
    pout[i] /= totout;
  }
  dfs(1);
  printf("%.12lf\n", ans);
  return 0;
}
