CF1930H.Interactive Mex Tree

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

输入格式

Each test contains multiple test cases. The first line contains a single integer tt ( 1t1041 \leq t \leq 10^4 ) — the number of test cases. Read it. The description of the test cases follows.

The first line of each test case contains two positive integers nn and qq ( 2n1052 \leq n \leq 10^5 , 1q1041 \leq q \leq 10^4 ) — the number of nodes in TT and the number of rounds respectively.

The following next n1n-1 lines contains two integers uu and vv ( 1u,vn1 \leq u, v \leq n , uvu \neq v ) — denoting an edge between nodes uu and vv . It is guaranteed that the given edges form a tree.

It is guaranteed that the sum of nn and qq over all test cases does not exceed 10510^5 and 10410^4 respectively.

It is also guaranteed that the sum of nqn \cdot q does not exceed 31063 \cdot 10^6 .

The interaction for each test case begins by outputting two permutations p1p_1 and p2p_2 of [1,2,,n][1, 2, \ldots, n] .

On a new line, output nn space-separated distinct integers denoting p1p_1 .

In the next line, output nn space-separated distinct integers denoting p2p_2 .

Alice will start playing the game.

For each round, you must read two integers, uu and vv ( 1u,vn1 \leq u, v \leq n , uvu \neq v ). You need to find the MEX\operatorname{MEX} of the values on the unique simple path between nodes uu and vv .

To make a query, output "? tt ll rr " without quotes, such that tt is either 11 or 22 , and 1lrn1 \leq l \leq r \leq n . Afterwards, you should read a single integer — the answer to your query mini=lrapt,i\min_{i=l}^{r} a_{p_{t,i}} . You can make at most 55 such queries in each round.

If you want to print the answer, output "! xx " ( 1x,yn1 \leq x, y \leq n ) without quotes. After doing that, read a single integer, which is normally equal to 11 .

If you receive the integer 1-1 instead of a valid reply, it means your program has made an invalid query, exceeded the query limit, or gave an incorrect answer on the previous test case. Your program must terminate immediately to receive a Wrong Answer verdict. Otherwise, you can get an arbitrary verdict because your solution will continue to read from a closed stream.

After printing a query or the answer, do not forget to output the end of the line and flush the output. Otherwise, you will get Idleness limit exceeded. To do this, use:

  • fflush(stdout) or cout.flush() in C++;
  • System.out.flush() in Java;
  • flush(output) in Pascal;
  • stdout.flush() in Python;
  • see documentation for other languages.

Hacks

To hack, follow the test format below.

The first line should contain a single integer tt ( 1t1041 \le t \le 10^4 ) — the number of test cases.

The first line of each test case should contain two positive integers nn and qq ( 2n1052 \leq n \leq 10^5 ; 1q1041 \leq q \leq 10^4 ) — the number of nodes in TT and the number of rounds respectively.

The following next n1n-1 lines should contain two integers uu and vv ( 1u,vn1 \leq u, v \leq n , uvu \neq v ) — denoting an edge between nodes uu and vv . The given edges must form a tree.

For each of the qq rounds, first print a permutation of [0,1,2,,n1][0, 1, 2, \ldots, n-1] on a new line, denoting the array aa chosen by Alice during the start of the round.

In the following line, print two distinct nodes uu and vv ( 1u,vv1 \leq u, v \leq v , uvu \neq v ), representing the endpoints of the path asked by Alice.

The sum of nn and qq over all test cases should not exceed 10510^5 and 10410^4 respectively.

The sum of nqn \cdot q should not exceed 31063 \cdot 10^6 .

输出格式

In the first test, the interaction proceeds as follows.

SolutionJuryExplanation1There are 1 test cases.3 1The tree TT consists of 33 nodes, and Alice will play for only one round.1 2First edge of TT 2 3Second edge of TT 1 2 3The permutation p1p_1 2 1 3The permutation p2p_2 Alice shuffles aa to a=[0,2,1]a=[0,2,1] before giving the nodes for the only round.2 3Nodes for the round? 1 2 31 min(ap1,2,ap1,3)=min(a2,a3)=1\min(a_{p_{1,2}},a_{p_{1,3}})=\min(a_2,a_3)=1 ? 2 1 30 min(ap2,1,ap2,2,ap2,3)=min(a2,a1,a3)=0\min(a_{p_{2,1}},a_{p_{2,2}},a_{p_{2,3}})=\min(a_2,a_1,a_3)=0 ! 01Considering the output of queries, it is clear that MEX\operatorname{MEX} is 00 . Since the output is correct, the jury responds with 11 .After each test case, make sure to read 11 or 1-1 .

输入输出样例

  • 输入#1

    1
    3 1
    1 2
    2 3
    
    
    2 3
    
    1
    
    0
    
    1

    输出#1

    1 2 3
    2 1 3
    
    ? 1 2 3
    
    ? 2 1 3
    
    ! 0

说明/提示

In the first test, the interaction proceeds as follows.

SolutionJuryExplanation1There are 1 test cases.3 1The tree TT consists of 33 nodes, and Alice will play for only one round.1 2First edge of TT 2 3Second edge of TT 1 2 3The permutation p1p_1 2 1 3The permutation p2p_2 Alice shuffles aa to a=[0,2,1]a=[0,2,1] before giving the nodes for the only round.2 3Nodes for the round? 1 2 31 min(ap1,2,ap1,3)=min(a2,a3)=1\min(a_{p_{1,2}},a_{p_{1,3}})=\min(a_2,a_3)=1 ? 2 1 30 min(ap2,1,ap2,2,ap2,3)=min(a2,a1,a3)=0\min(a_{p_{2,1}},a_{p_{2,2}},a_{p_{2,3}})=\min(a_2,a_1,a_3)=0 ! 01Considering the output of queries, it is clear that MEX\operatorname{MEX} is 00 . Since the output is correct, the jury responds with 11 .After each test case, make sure to read 11 or 1-1 .

首页