#P5529. [Ynoi2012] 梦断 SCOI2017

[Ynoi2012] 梦断 SCOI2017

Description

There are nn students forming a rooted tree, and each student has a gpa\text{gpa}.

Define a student’s major as the connected component that contains this student after keeping only the edges whose two endpoints have the same gpa\text{gpa}.

Define the resentment value of a major as max(dep[a]dep[b]+1)max(dep[a]-dep[b]+1) s.ts.t. a,ba,b are students in the major, deproot=0dep_{root}=0, and depw=depws father+1dep_{w}=dep_{w's\ father}+1.

Operation 1: given xx and yy, change student xx’s gpa\text{gpa} to yy.

Operation 2: given xx and yy, change the gpa\text{gpa} of all nodes in the major containing student xx to yy.

Operation 3: given xx, ask for student xx’s gpa\text{gpa}, the number of students in the major containing xx, and the resentment value of the major containing xx.

Input Format

The first line contains an integer nn.

The second line contains nn integers representing the parent of each node. The ii-th integer is <i< i, and the parent of node 11 is 00.

The third line contains nn integers representing each student’s gpa\text{gpa}.

The fourth line contains an integer mm.

Then follow mm lines. Each line contains two or three integers representing one operation, with types as described above.

Output Format

For each operation of type 33, output one line with three integers separated by spaces, in order: student xx’s gpa\text{gpa}, the number of students in the major containing xx, and the resentment value of the major containing xx.

10
0 1 1 1 3 4 2 4 2 3
16 20 29 16 23 6 29 21 1 22
10
3 4
3 4
2 6 20
2 1 8
2 2 8
1 9 21
3 6
3 2
1 3 11
1 4 17

16 2 2
16 2 2
20 1 1
8 3 2

Hint

Idea: ccz181078, Solution: ccz181078, Code: ccz181078, Data: ccz181078

Assume there are a total of cc kinds of gpa\text{gpa}.

For 40%40\% of the testdata, n,m1000n,m \le 1000.

For another 40%40\% of the testdata, n,m105n,m \le 10^{5}, c=2c=2, and gpa\text{gpa} is in [1,2][1,2].

For 100%100\% of the testdata, n,m105n,m \le 10^5, c=30c=30, and gpa\text{gpa} is in [1,30][1,30].

I am too lazy to even complain about THU.

Translated by ChatGPT 5