QOJ.ac

QOJ

时间限制: 2 s 内存限制: 1024 MB 总分: 100

#3006. 堆的乐趣

统计

考虑一棵有 $n$ 个节点的有根树,节点编号为 $1 \cdots n$。每个节点都有一个固定的整数 $b$,且每个节点都会在区间 $[0, b]$ 中均匀随机选择一个实数。

这棵树形成一个(即每个节点上的随机值都小于其所有子节点上的随机值)的概率是多少?

该概率总能表示为一个有理数 $\frac{P}{Q}$,其中 $Q \not\equiv 0 \pmod{10^9+7}$。你需要输出该概率对 $10^9+7$ 取模的结果,即 $P \times Q^{-1} \bmod{(10^9+7)}$,其中 $Q^{-1}$ 是 $Q$ 在模 $10^9+7$ 意义下的乘法逆元(满足 $Q \times Q^{-1} \equiv 1 \pmod{10^9+7}$)。(注意:$P \times Q^{-1} \bmod{(10^9+7)}$ 的结果与 $P$ 和 $Q$ 是否互质无关,仅取决于它们的比值 $\frac{P}{Q}$。)

输入格式

每个测试用例的第一行包含一个整数 $n$ ($1 \leq n \leq 300$),表示树的节点数。

接下来的 $n$ 行,每行包含一对空格分隔的整数 $b$ ($1 \leq b \leq 10^9$) 和 $p$ ($0 \leq p \leq n$),描述树的一个节点。其中 $b$ 是该节点固定的整数值,$p$ 是其父节点的编号。节点按顺序给出:第一行对应节点 $1$,第二行对应节点 $2$,以此类推。其中一个节点的父节点为 $p=0$,这是树的根节点。

输出格式

输出一个整数,即概率对 $10^9+7$ 取模的结果。

样例

样例输入 1

2
1000000000 0
1000000000 1

样例输出 1

500000004

样例输入 2

5
2 3
2 3
1 0
2 3
2 3

样例输出 2

87500001

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.