#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const int mod = 998244353;
void reduce(int &a) { a += a >> 31 & mod; }
int Mod(int x) { return x >= mod ? x - mod : x; }
int read() {
  int x = 0;
  int f = 1;
  char ch = getchar();
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') f = -1;
  for (; isdigit(ch); ch = getchar()) x = x * 10 + (ch ^ 48);
  return x * f;
}
void print(long long x) {
  if (x < 0) putchar('-'), x = -x;
  if (x > 9) print(x / 10);
  putchar(x % 10 + '0');
}
const int N = 100010, M = N;
int n;
;
struct edge {
  int nxt, to, w;
} e[M << 1];
int head[N], ecnt = 1;
void add(int u, int v, long long w = 0) {
  e[++ecnt].w = w, e[ecnt].to = v, e[ecnt].nxt = head[u];
  head[u] = ecnt;
}
void add_edge(int u, int v, long long w = 0) {
  add(u, v, w), add(v, u, w * 1);
};
double x[N], y[N], tx, ty;
double sum[N], siz[N], ans;
void dfs(int u, int fa) {
  siz[u] = 1, sum[u] = x[u];
  double res = 0;
  for (int i = head[u], v; i; i = e[i].nxt)
    if ((v = e[i].to) != fa) {
      dfs(v, u);
      siz[u] += siz[v];
      sum[u] += sum[v];
      res += sum[v] * siz[v];
    }
  res += (1 - sum[u]) * (n - siz[u]);
  ans += res * y[u];
}
int main() {
  n = read();
  for (int i = 1; i < n; i++) add_edge(read(), read());
  for (int i = 1; i <= n; i++) tx += (x[i] = read()), ty += (y[i] = read());
  for (int i = 1; i <= n; i++) x[i] /= tx, y[i] /= ty;
  dfs(1, 0), printf("%.9lf\n", ans);
}
