eolymp
bolt
Try our new interface for solving problems
Məsələlər

Happy Painting!

Happy Painting!

There is a forest of colorful rooted trees containing \textbf{n} nodes. You are given \textbf{m} operations. Execute them one by one, and output the results. \InputFile The input contains several test cases. The first line of each test case contains two integers \textbf{n} and \textbf{m} (\textbf{1} ≤ \textbf{n} ≤ \textbf{50,000}, \textbf{1} ≤ \textbf{m} ≤ \textbf{200,000}). Nodes are numbered from \textbf{1} to \textbf{n}. The second line contains \textbf{n} integers \textbf{F}\[\textbf{i}\] (\textbf{0} ≤ \textbf{F}\[\textbf{i}\] ≤ \textbf{n}), the father of each node (\textbf{F}\[\textbf{i}\] = \textbf{0} means the node is the root of a tree). The next line contains n integers \textbf{C}\[\textbf{i}\] (\textbf{1} ≤ \textbf{C}\[\textbf{i}\] ≤ \textbf{30}), the colors of the edges between each node and its father (for root nodes, the corresponding color should be ignored). Each of the next m lines contains an operation. For all operations, \textbf{1} \textbf{<=} \textbf{x}, \textbf{y} ≤ \textbf{n}, for each type-\textbf{2} operation, \textbf{1} ≤ \textbf{c} ≤ \textbf{30}. The input is terminated by end-of-file (\textbf{EOF}). The size of input file does not exceed \textbf{5} MB. \OutputFile For each type-\textbf{3} operation, output two integers: the number of edges and the number of colors among these edges.
Zaman məhdudiyyəti 3 saniyə
Yaddaşı istafadə məhdudiyyəti 64 MiB
Giriş verilənləri #1
6 6
0 1 1 3 3 0
1 2 1 1 1 1
3 2 3
1 3 2 3
3 2 3
3 5 6
1 6 1 1
3 4 6
Çıxış verilənləri #1
2 2
1 1
0 0
4 3