#include #include #include using namespace std; typedef long double ld; const int MAXN = 55; int n, col[MAXN], a[MAXN], dep[MAXN], D[MAXN], p[MAXN]; int tot, Last[MAXN], Next[MAXN * 2], Go[MAXN * 2]; ld f[MAXN], c[MAXN][MAXN]; void link(int u, int v) { Next[++ tot] = Last[u], Last[u] = tot, Go[tot] = v; } void Dfs(int now, int pre) { int goal = 0; dep[now] = dep[pre] + 1; for (int i = 1; i <= D[0]; i ++) if (dep[now] - dep[D[i]] <= a[D[i]]) goal^= p[D[i]]; if (col[now] ^ goal == 0) p[now] = 1; D[++ D[0]] = now; for (int p = Last[now]; p; p = Next[p]) { int v = Go[p]; if (v == pre) continue; Dfs(v, now); } D[0] --; } void Solve() { memset(f, 0, sizeof f); for (int i = n - 1; i >= 0; i --) { for (int j = 0; j <= n; j ++) if (i != j) f[i] += c[i][j] * f[j]; f[i] = (-(f[i] + c[i][n + 1])) / c[i][i]; } } void solve() { tot = 0; memset(Last, 0, sizeof Last); scanf("%d", &n); for (int i = 1; i < n; i ++) { int u, v; scanf("%d%d", &u, &v); link(u, v), link(v, u); } for (int i = 1; i <= n; i ++) scanf("%d", &col[i]); for (int i = 1; i <= n; i ++) scanf("%d", &a[i]); memset(p, 0, sizeof p); Dfs(1, 0); memset(c, 0, sizeof c); c[n][n] = 1; ld nn = (ld)n; for (int i = 0; i < n; i ++) c[i][i] = 1; for (int i = 0; i < n; i ++) c[i][i + 1] = -(n - i) / nn; for (int i = 1; i < n; i ++) c[i][i - 1] = -i / nn; for (int i = 0; i < n; i ++) c[i][n + 1] = -1; for (int i = 0, j = 0; i <= n && j <= n; j ++) { for (int k = i; k <= n; k ++) { if (c[k][j]) { swap(c[i], c[k]); break; } } if (!c[i][j]) continue; for (int k = i + 1; k <= n; k ++) { if (c[k][j]) { ld tt = c[k][j] / c[i][j]; for (int l = j; l <= n + 1; l ++) c[k][l] = c[k][l] - c[i][l] * tt; } } i ++; } Solve(); int num = 0; for (int i = 1; i <= n; i ++) if (!p[i]) num ++; printf("%.3lf\n", double(f[num])); } int main() { int t; scanf("%d", &t); for (int i = 1; i <= t; i ++) solve(); }