QOJ.ac

QOJ

Time Limit: 1.5 s Memory Limit: 2048 MB Total points: 100 Hackable ✓

#14579. 火花

الإحصائيات
愛し方さえも 君の匂いがした
即便是爱你的时候 也散发你的味道
歩き方さえも その笑い声がした
甚至连走路的时候 也充斥你那样的笑声

题目描述

  • 有一棵 $n$ 个点、根为 $1$ 的树。第 $i$ 个点上有 $c_i$ 个物品,权值均为 $v_i$。
  • 需要先选择 $t$ 个不同的点,对于选的每个点,在它的每个祖先(包括自己)上各取一个物品。
    • 本题保证 $\boldsymbol{t \lt c_i}$,因此不会存在没有物品可取的情况。
  • 接下来可以取至多 $k$ 个物品,要求所有在这一步被取了物品的点形成一个含根的连通块。
  • 最大化整个过程中取的物品权值之和。

输入格式

  • 第一行三个整数 $n, k, t$。
  • 接下来 $n$ 行,每行两个正整数分别表示 $c_i$ 和 $v_i$。
  • 最后一行 $n - 1$ 个正整数,第 $i$ 个正整数表示点 $(i + 1)$ 在树上的父亲 $\mathrm{fa}_{i + 1}$。

输出格式

  • 一行,输出一个非负整数,表示最大的权值和。

样例

样例 1 输入
4 4 1
2 1 
2 1
2 5
2 1
1 1 2
样例 1 输出
15

数据范围

对于所有数据:$1 \leq n, k \leq 10^4$,$0\leq t \leq n$,$\boldsymbol{t \lt c_i} \leq 10^9$,$1\leq v_i \leq 10^9$,$\mathrm{fa}_i \lt i$,$nk(t+1)\leq 10^7$。

  • 子任务 1(10 分):$n, k, t \leq 10$。
  • 子任务 2(20 分):$t = 0$。
  • 子任务 3(15 分):$n k (t + 1) \leq 10^6$。
  • 子任务 4(25 分):$n k (t + 1) \leq 5 \times 10^6$。
  • 子任务 5(30 分):无特殊限制。
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.