QOJ.ac

QOJ

حد الوقت: 1 s حد الذاكرة: 512 MB مجموع النقاط: 100

#9532. Naganohara Ryuusei Meteor Shower

الإحصائيات

Naganohara Yoimiya has given you a rooted tree with $n$ nodes, where node $1$ is the root and each node $i$ has a weight $w_i$.

For each node $u$, you need to find a non-empty connected subgraph (a subtree in the context of the rooted structure) that includes $u$ as its root, such that the average of the weights of all nodes in this connected subgraph is maximized.

Output this maximum average for each node $u$.

Input

The first line contains a positive integer $n$.

The next line contains $n-1$ positive integers $p_2, p_3, \dots, p_n$, where $p_i$ is the parent of node $i$. It is guaranteed that $p_i < i$.

The next line contains $n$ positive integers $w_1, w_2, \dots, w_n$.

Output

Output $n$ lines, where the $i$-th line contains a real number representing the maximum average weight of a connected subgraph rooted at node $i$.

Your answer will be considered correct if the relative or absolute error does not exceed $10^{-6}$.

Constraints

For all test cases, $1 \le n \le 2 \times 10^5$, $1 \le w_i \le 10^9$.

  • Subtask 1 ($10$ points): $1 \le n \le 2000$.
  • Subtask 2 ($10$ points): $p_i = \lfloor i/2 \rfloor$.
  • Subtask 3 ($40$ points): $1 \le n \le 50000$.
  • Subtask 4 ($40$ points): No additional constraints.

Examples

Input 1

6
1 2 2 1 4
3 1 5 6 6 7

Output 1

4.6666666667
4.7500000000
5.0000000000
6.5000000000
6.0000000000
7.0000000000

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
EditorialOpen Official EditorialQingyu- Download

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.