#P16100. [ICPC 2019 NAIPC] Heaps of Fun

[ICPC 2019 NAIPC] Heaps of Fun

题目描述

Consider a rooted tree with nn nodes, numbered 1..n1..n. Each node will have a fixed integer bb, and for each, a uniform random real number is chosen in the interval [0..b][0..b].

What is the probability that the random numbers chosen cause the tree to form a Heap (i.e., the random value in each node is less than the random values in its children)?

This probability can always be expressed as a rational number PQ\frac{P}{Q}, with Q≢0(mod109+7)Q \not\equiv 0 \pmod{10^9+7}. You are to output the probability as PQ1mod109+7P \cdot Q^{-1} \bmod 10^9+7, where Q1Q^{-1} is an integer, which is the multiplicative inverse of QQ modulo 109+710^9+7 (QQ11(mod109+7)Q \cdot Q^{-1} \equiv 1 \pmod{10^9+7}). (Note: PQ1mod109+7P \cdot Q^{-1} \bmod 10^9+7 does not depend on whether PP and QQ are relatively prime, only on their ratio PQ\frac{P}{Q}.)

输入格式

Each test case will begin with a line with a single integer nn (1n3001 \leq n \leq 300), which is the number of nodes in the tree.

Each of the next nn lines will contain a pair of space-separated integers bb (1b1091 \leq b \leq 10^9) and pp (0pn0 \leq p \leq n) describing a node of the tree, where bb is the fixed integer value in the node and pp is the node number of its parent. The nodes are listed in order; node 1 is first, then node 2, and so on. A single node will have a parent p=0p = 0. This is the root of the tree.

输出格式

Output a single integer, which is the probability expressed as (PQ1)mod(109+7)(P \cdot Q^{-1}) \bmod (10^9+7).

2
1000000000 0
1000000000 1
500000004
5
2 3
2 3
1 0
2 3
2 
87500001