#P9168. [省选联考 2023] 人员调度

[省选联考 2023] 人员调度

Background

Abusing the judging system for this problem will result in a ban.

Problem Description

As is well known, the nn departments of a company can be organized into a tree structure. Formally, suppose these departments are numbered 1,,n1, \ldots, n in order. Then, except for department 11, each department i[2,n]i \in [2, n] has exactly one direct superior department pi[1,i1]p_i \in [1, i - 1]. In this way, the nn departments of the company can be viewed as a rooted tree with root 11. If ii is a node in the subtree of jj, then department ii is called a sub-department of department jj.

Initially, the company has kk outstanding employees, numbered 1k1 \ldots k. The ii-th outstanding employee initially works in department xix_i and has an ability value vi>0v_i > 0.

To maximize the company's operational efficiency, the boss 0/\/\G decides to make some personnel transfers. Specifically, the outstanding employee with number ii can be transferred to a sub-department of xix_i, or not transferred (in which case the employee stays in department xix_i). After that, the outstanding employees will compete to become the leader of their department—the one with the highest ability value will take the position and bring a contribution equal to their ability value to the company. If a department has no outstanding employees at all, then no leader can be chosen, and its contribution will be 00. The company's performance is defined as the sum of contributions of all departments.

Naturally, the boss 0/\/\G wants to know how to transfer employees to maximize the company's performance.

This is not difficult for him. However, the number of outstanding employees may also change. Specifically, there will be mm events in order, each of one of the following forms:

  • 1 x v: First set k=k+1k = k + 1, then add a new outstanding employee numbered kk, whose initial department is xx and ability value is vv.
  • 2 id: The outstanding employee numbered id\mathit{id} will be fired.

The boss 0/\/\G wants you to tell him, at the beginning and after each event, what the maximum possible company performance is.

Note that each round of personnel transfers is independent. That is, each time you compute the maximum possible performance, every outstanding employee returns to their own initial department.

Input Format

The first line contains a positive integer sid\mathit{sid}, indicating the constraints and special properties for this test point. See the table below for details.

The second line contains three integers n,k,mn, k, m, representing the number of departments, the initial number of outstanding employees, and the number of events.

The third line contains n1n - 1 positive integers p2,,pnp_2, \ldots, p_n, representing the direct superior department of each department.

The next kk lines each contain two positive integers xi,vix_i, v_i, representing the initial department and ability value of an outstanding employee.

The next mm lines each describe an event in the form 1 x v or 2 id.

Output Format

Output one line containing m+1m + 1 non-negative integers separated by single spaces, representing the maximum possible company performance at the beginning and after each event, in order.

1
3 2 1
1 1
2 1
1 3
1 2 2

4 5

见附件中的 transfer/transfer2.in
见附件中的 transfer/transfer2.ans
见附件中的 transfer/transfer3.in
见附件中的 transfer/transfer3.ans
见附件中的 transfer/transfer4.in
见附件中的 transfer/transfer4.ans
见附件中的 transfer/transfer5.in
见附件中的 transfer/transfer5.ans
见附件中的 transfer/transfer6.in
见附件中的 transfer/transfer6.ans
见附件中的 transfer/transfer7.in
见附件中的 transfer/transfer7.ans
见附件中的 transfer/transfer8.in
见附件中的 transfer/transfer8.ans
见附件中的 transfer/transfer9.in
见附件中的 transfer/transfer9.ans
见附件中的 transfer/transfer10.in
见附件中的 transfer/transfer10.ans
见附件中的 transfer/transfer11.in
见附件中的 transfer/transfer11.ans
见附件中的 transfer/transfer12.in
见附件中的 transfer/transfer12.ans
见附件中的 transfer/transfer13.in
见附件中的 transfer/transfer13.ans
见附件中的 transfer/transfer14.in
见附件中的 transfer/transfer14.ans
见附件中的 transfer/transfer15.in
见附件中的 transfer/transfer15.ans

Hint

【Constraints】

For all testdata, it is guaranteed that: 1sid151 \le \mathit{sid} \le 15, 1n,k1051 \le n, k \le 10^5, 0m1050 \le m \le 10^5, 1pi<i1 \le p_i < i, 1xi,xn1 \le x_i, x \le n, 1vi,v1051 \le v_i, v \le 10^5.

For event type 2, it is guaranteed that: 1idk1 \le \mathit{id} \le k, and the employee with number id\mathit{id} is still employed when this event happens.

Test Point ID sid\mathit{sid} nn \le kk \le mm \le Special Properties
1 11 66 66 None
2, 3 22 99
4, 5 33 1616 6666 6666
6 ~ 8 44 6666 00
9 ~ 11 55 2,3332,333
12 ~ 14 66 10510^5 B
15 ~ 18 77 None
19 ~ 21 88 2,3332,333 A
22 ~ 24 99 10510^5 AB
25 ~ 28 1010 A
29 ~ 31 1111 2,3332,333 None
32 ~ 34 1212 10510^5 C
35 ~ 38 1313 B
39 ~ 44 1414 66,66666,666 None
45 ~ 50 1515 10510^5

Special Property A: There are no events of type 2.

Special Property B: pi=i1p_i = i - 1.

Special Property C: vi=v=1v_i = v = 1.

Translated by ChatGPT 5