#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100005;
template <typename T>
inline void read(T &AKNOI) {
  T x = 0, flag = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') flag = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  AKNOI = flag * x;
}
int n, st[MAXN], ed[MAXN], ssum, esum, siz[MAXN];
long long ans;
struct Edge {
  int v, nxt;
} e[MAXN << 1];
int first[MAXN], eCnt;
inline void AddEdge(int u, int v) {
  e[++eCnt].v = v;
  e[eCnt].nxt = first[u];
  first[u] = eCnt;
}
void DFS(int u, int fa) {
  siz[u] = 1;
  for (int i = first[u]; i; i = e[i].nxt) {
    int v = e[i].v;
    if (v == fa) continue;
    DFS(v, u);
    ans += 1LL * st[v] * siz[v] * ed[u];
    siz[u] += siz[v];
    st[u] += st[v];
  }
  ans += 1LL * (ssum - st[u]) * (n - siz[u]) * ed[u];
}
void init() {
  read(n);
  for (int i = 1, u, v; i < n; ++i) {
    read(u);
    read(v);
    AddEdge(u, v);
    AddEdge(v, u);
  }
  for (int i = 1; i <= n; ++i) {
    read(st[i]);
    read(ed[i]);
    ssum += st[i];
    esum += ed[i];
  }
}
void solve() {
  DFS(1, 0);
  printf("%.10lf\n", 1.0 * ans / ssum / esum);
}
int main() {
  init();
  solve();
  return 0;
}
