#P5529. [Ynoi2012] 梦断 SCOI2017
[Ynoi2012] 梦断 SCOI2017
Description
There are students forming a rooted tree, and each student has a .
Define a student’s major as the connected component that contains this student after keeping only the edges whose two endpoints have the same .
Define the resentment value of a major as . are students in the major, , and .
Operation 1: given and , change student ’s to .
Operation 2: given and , change the of all nodes in the major containing student to .
Operation 3: given , ask for student ’s , the number of students in the major containing , and the resentment value of the major containing .
Input Format
The first line contains an integer .
The second line contains integers representing the parent of each node. The -th integer is , and the parent of node is .
The third line contains integers representing each student’s .
The fourth line contains an integer .
Then follow lines. Each line contains two or three integers representing one operation, with types as described above.
Output Format
For each operation of type , output one line with three integers separated by spaces, in order: student ’s , the number of students in the major containing , and the resentment value of the major containing .
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 kinds of .
For of the testdata, .
For another of the testdata, , , and is in .
For of the testdata, , , and is in .
I am too lazy to even complain about THU.
Translated by ChatGPT 5
京公网安备 11011102002149号