#include <bits/stdc++.h>
template <class T>
void next_num(T &num) {
  char c;
  bool is_minus = false;
  while ((c = getchar())) {
    if (c == '-') is_minus = true;
    if (c >= '0' && c <= '9') {
      num = c - '0';
      while ((c = getchar()) && c >= '0' && c <= '9') num = num * 10 + c - '0';
      ungetc(c, stdin);
      if (is_minus) num = -num;
      break;
    }
  }
}
const int MAXN = 100000;
int n, u, v;
int x[MAXN + 5], y[MAXN + 5];
int sumx, sumy;
int size[MAXN + 5];
double ans;
const int MAXEDGE = MAXN * 2;
const int MAXNODE = MAXN;
struct node {
  node *next;
  int v;
} edge[MAXEDGE + 5], *adj[MAXNODE + 5], *ecnt = edge;
void addedge(int u, int v) {
  node *p = ecnt;
  p->next = adj[u];
  p->v = v;
  adj[u] = p;
  ++ecnt;
}
void dfs(int u, int fa) {
  size[u] = 1;
  for (node *p = adj[u]; p != NULL; p = p->next)
    if (p->v != fa) {
      dfs(p->v, u);
      size[u] += size[p->v];
      x[u] += x[p->v];
      ans += 1.0 * x[p->v] * size[p->v] * y[u];
    }
  ans += 1.0 * (sumx - x[u]) * (n - size[u]) * y[u];
}
int main() {
  next_num(n);
  for (int i = 1; i <= n - 1; ++i) {
    next_num(u), next_num(v);
    addedge(u, v);
    addedge(v, u);
  }
  for (int i = 1; i <= n; ++i) {
    next_num(x[i]), next_num(y[i]);
    sumx += x[i], sumy += y[i];
  }
  dfs(1, -1);
  printf("%.11lf\n", ans / sumx / sumy);
}
