#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long w = 0, x = 0;
  char c = getchar();
  while (!isdigit(c)) w |= c == '-', c = getchar();
  while (isdigit(c)) x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
  return w ? -x : x;
}
namespace star {
const long long maxn = 1e5 + 10;
long long n, x[maxn], y[maxn], sx, sy;
long long ecnt, head[maxn], to[maxn << 1], nxt[maxn << 1], siz[maxn], ans;
inline void addedge(long long a, long long b) {
  to[++ecnt] = b, nxt[ecnt] = head[a], head[a] = ecnt;
  to[++ecnt] = a, nxt[ecnt] = head[b], head[b] = ecnt;
}
void dfs(long long v, long long fa) {
  siz[v] = 1;
  for (long long i = head[v]; i; i = nxt[i]) {
    long long u = to[i];
    if (u == fa) continue;
    dfs(u, v);
    x[v] += x[u];
    siz[v] += siz[u];
    ans += 1LL * y[v] * x[u] * siz[u];
  }
  ans += 1LL * y[v] * (sx - x[v]) * (n - siz[v]);
}
inline void work() {
  n = read();
  for (long long i = 1; i < n; i++) addedge(read(), read());
  for (long long i = 1; i <= n; i++)
    sx += (x[i] = read()), sy += (y[i] = read());
  dfs(1, 1);
  printf("%.15lf\n", 1.0 * ans / sx / sy);
}
}  // namespace star
signed main() {
  star::work();
  return 0;
}
