Long: WCWBTT

아직 제출이 없습니다시간 제한20초메모리 제한1024 MB

문제

This is an interactive problem.

You need to maintain a rooted tree with vertex 11 as the root. The tree has nn vertices, and the parent of vertex ii (2in2 \le i \le n) is p_ip\_i (1p_i<i1 \le p\_i < i).

You have to process qq queries, each in one of the following forms:

  • "? aa bb": Output the set SS, where SS is the set consisting of all vertices on the unique simple path from aa to bb.
  • "= aa bb": Change the parent of aa to bb (that is, p_abp\_a \leftarrow b). It is guaranteed that the vertices still form a tree after the modification, but it is not guaranteed that b\<ab\<a.

But you soon discover a problem: the size of the set SS may be too large, you can't output all elements in each query.

To deal with this issue, you have designed a special computer. This special computer can maintain sets of integers and operate on them quickly. Initially, the computer has only n+1 sets S_0,S_1,,S_nS\_0, S\_1, \ldots, S\_{n} where the set S_0=S\_0 = \varnothing, and S_i=iS\_i = \\{i\\} for all 1in1 \le i \le n.

This computer is efficient and at the same time very simple: it supports only two different operations!

  • "+ aa bb": Construct a new set S_c=S_aS_bS\_c = S\_a \cup S\_b (S_aS_b=S\_a \cap S\_b = \varnothing), with cc being the maximum of the ID of all sets plus one. You have to make sure that S_aS_b=S\_a \cap S\_b = \varnothing. The cost of this operation is S_a+S_b|S\_a| + |S\_b|.
  • "! kk x_1x\_1 x_2x\_2 \ldots x_kx\_k": Print the set S_x_1S_x_2S_x_kS\_{x\_1} \cup S\_{x\_2} \cup \cdots \cup S\_{x\_k} as the answer to the query. You need to ensure that S_x_iS_x_j=S\_{x\_i} \cap S\_{x\_j} = \varnothing for all 1i<jk1 \le i < j \le k. The cost of this operation is kk.

Now, you need to use this computer to maintain the rooted tree. In order to avoid calculations consuming too much time and causing damage to the computer, there are the following restrictions when using the computer.

  • The cost of each operation cannot exceed 70007000.
  • The sum of the cost of all operations cannot exceed 7.51077.5 \cdot 10^7.
  • The total number of operations cannot exceed 51065 \cdot 10^6.

입력

The first line of the input contains two integers nn and qq (1n21051 \le n \le 2 \cdot 10^5, 1q2.51041 \le q \le 2.5 \cdot 10^4).

The next line of the input contains n1n-1 integers p_2,p_3,,p_np\_2, p\_3, \ldots, p\_n (1p_i<i1 \le p\_i < i), indicating the initial parent of each vertex.

힌트

The sample input and output are intended only to illustrate the interaction protocol. The string "<flush the output>" and the blank lines are only added for the reader's convenience. You should not output this information.

Here's the figure of the sample test case:

The figure corresponds to the sample test case

  • S_0=S\_0 = \varnothing
  • S_1=1S\_1 = \\{1\\}
  • S_2=2S\_2 = \\{2\\}
  • S_3=3S\_3 = \\{3\\}
  • S_4=1,2S\_4 = \\{1, 2\\}
  • S_5=1,2,3S\_5 = \\{1, 2, 3\\}
  • S_6=1,2S\_6 = \\{1, 2\\}
  • S_7=1,3S\_7 = \\{1, 3\\}