#include<cstdio> #include<cctype> #include<algorithm> #include<cstring> #include<vector> intread(){ registerint x = 0; registerchar f = 1, ch = getchar(); for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = !f; for (; isdigit(ch); ch = getchar()) x = (x << 3) + (x << 1) + (ch ^ '0'); return f ? x : -x; } #define N 305 #define P 1000000007 int n, m, a[N], b[N], fa[N], rt, inv[N], inva[N], sz[N], dp[N][N][N], tmp[N]; std :: vector<int> E[N]; intqpow(int a, int b){ int s = 1; for (; b; b >>= 1, a = 1ll * a * a % P) if (b & 1) s = 1ll * s * a % P; return s; } voidadd(int &x, int y){ (x += y) >= P ? x -= P : 0; } voiddfs(int u){ sz[u] = 1; for (registerint i = 0; i < b[u]; ++i) dp[u][i][1] = 1ll * (a[i + 1] - a[i]) * inva[b[u]] % P; for (registerint i = 0; i < E[u].size(); ++i){ int v = E[u][i], sum = 0; dfs(v); for (registerint j = b[v] - 1; j >= b[u]; --j) for (registerint k = 1; k <= sz[v]; ++k) add(sum, dp[v][j][k]); for (registerint j = b[u] - 1; ~j; --j){ for (registerint k = 1; k <= sz[u] + sz[v]; ++k) tmp[k] = 0; for (registerint k = 1; k <= sz[u]; ++k) for (registerint l = 1; l <= sz[v]; ++l) add(tmp[k + l], 1ll * dp[u][j][k] * dp[v][j][l] % P); for (registerint k = 1; k <= sz[u] + sz[v]; ++k) dp[u][j][k] = (1ll * dp[u][j][k] * sum + tmp[k]) % P; for (registerint k = 1; k <= sz[v]; ++k) add(sum, dp[v][j][k]); } sz[u] += sz[v]; } for (registerint j = 0; j < b[u]; ++j) for (registerint k = 1; k <= sz[u]; ++k) dp[u][j][k] = 1ll * dp[u][j][k] * inv[k] % P; } intmain(){ freopen("a.in", "r", stdin); freopen("a.out", "w", stdout); n = read(); for (registerint i = 1; i <= n; ++i){ a[i] = b[i] = read(), fa[i] = read(); if (fa[i]) E[fa[i]].push_back(i); else rt = i; } std :: sort(a + 1, a + 1 + n); m = std :: unique(a + 1, a + 1 + n) - a - 1; for (registerint i = 1; i <= n; ++i) b[i] = std :: lower_bound(a + 1, a + 1 + m, b[i]) - a; for (registerint i = 1; i <= n; ++i) inv[i] = qpow(i, P - 2); for (registerint i = 1; i <= m; ++i) inva[i] = qpow(a[i], P - 2); dfs(rt); int ans = 0; for (registerint i = 0; i < b[rt]; ++i) for (registerint j = 1; j <= n; ++j) add(ans, dp[rt][i][j]); printf("%d", ans); }