#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int n, t, nxt[N << 1], head[N], adj[N << 1], sz[N], fa[N], x, y;
double in[N], out[N], Sin, Sout, ans;
void push(int u, int v) {
  nxt[++t] = head[u];
  head[u] = t;
  adj[t] = v;
}
void dfs(int u) {
  sz[u] = 1;
  for (int i = head[u]; i; i = nxt[i])
    if (adj[i] != fa[u]) {
      fa[adj[i]] = u;
      dfs(adj[i]);
      sz[u] += sz[adj[i]];
      in[u] += in[adj[i]];
    }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    scanf("%d%d", &x, &y);
    push(x, y), push(y, x);
  }
  for (int i = 1; i <= n; i++)
    scanf("%lf%lf", &in[i], &out[i]), Sin += in[i], Sout += out[i];
  for (int i = 1; i <= n; i++) in[i] /= Sin;
  dfs(1);
  for (int i = 1; i <= n; i++)
    for (int j = head[i]; j; j = nxt[j])
      if (adj[j] == fa[i])
        ans += (1 - in[i]) * (n - sz[i]) * out[i] / Sout;
      else
        ans += in[adj[j]] * sz[adj[j]] * out[i] / Sout;
  printf("%.11lf", ans);
}
