QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 512 MB Total points: 100

#9532. 长野原龙势流星群

统计

题目描述

Naganohara Yoimiya 给了你一棵 $n$ 个节点的有根树,$1$ 号节点是根节点,每个点有点权 $w_i$。

你需要对每个点 $u$ 找到一个以 $u$ 为根的非空连通块,并最大化这个连通块内所有点的点权的平均值。

对每个点 $u$ 输出这个最大的平均值。

输入格式

第一行一个正整数 $n$。

接下来一行 $n-1$ 个正整数 $p_2,p_3,\cdots,p_n$,$p_i$ 表示 $i$ 的父节点的编号,保证 $p_i< i$。

接下来一行 $n$ 个正整数 $w_1,w_2,\cdots,w_n$。

输出格式

输出 $n$ 行,第 $i$ 行输出一个实数表示以节点 $i$ 为根的连通块内点权平均值的最大值。

如果你的答案和标准答案的相对误差或绝对误差不超过 $10^{-6}$ 则视为正确。

样例 $1$ 输入

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

样例 $1$ 输出

4.6666666667
4.7500000000
5.0000000000
6.5000000000
6.0000000000
7.0000000000

测试点约束

对于所有数据,$1\le n\le 2\times 10^5,1\le w_i\le 10^9$。

  • Subtask 1($10$ 分):$1\le n\le 2000$。
  • Subtask 2($10$ 分):$p_i=\lfloor i/2\rfloor$。
  • Subtask 3($40$ 分):$1\le n\le 50000$。
  • Subtask 4($40$ 分):无特殊限制。
About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.