CF1592D.Hemose in ICPC ?

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

This is an interactive problem!

In the last regional contest Hemose, ZeyadKhattab and YahiaSherif — members of the team Carpe Diem — did not qualify to ICPC because of some unknown reasons. Hemose was very sad and had a bad day after the contest, but ZeyadKhattab is very wise and knows Hemose very well, and does not want to see him sad.

Zeyad knows that Hemose loves tree problems, so he gave him a tree problem with a very special device.

Hemose has a weighted tree with nn nodes and n1n-1 edges. Unfortunately, Hemose doesn't remember the weights of edges.

Let's define Dist(u,v)Dist(u, v) for uvu\neq v as the greatest common divisor of the weights of all edges on the path from node uu to node vv .

Hemose has a special device. Hemose can give the device a set of nodes, and the device will return the largest DistDist between any two nodes from the set. More formally, if Hemose gives the device a set SS of nodes, the device will return the largest value of Dist(u,v)Dist(u, v) over all pairs (u,v)(u, v) with uu , vv \in SS and uvu \neq v .

Hemose can use this Device at most 1212 times, and wants to find any two distinct nodes aa , bb , such that Dist(a,b)Dist(a, b) is maximum possible. Can you help him?

输入格式

输出格式

Begin the interaction from reading a single integer nn ( 2n1032 \le n \le 10^3 ) — the number of nodes in the tree.

Next, read n1n-1 lines.

The ii -th of the next n1n-1 lines contains two integers uiu_i and viv_i ( 1ui,vin1 \leq u_i, v_i \leq n , uiviu_i\neq v_i ), which means that there's an edge between nodes uiu_i and viv_i .

It's guaranteed that weights of edges were 109\leq 10^9 .

It is guaranteed that the given graph is a tree.

Now you may begin asking queries. To ask a query about a set of kk nodes v1,v2,,vkv_1, v_2, \ldots, v_k ( 2kn2 \le k \le n , 1vin1 \le v_i \le n , all viv_i are distinct), output:

? kk v1v_1 v2v_2 \ldots vkv_k

You will then receive an integer xx , the largest Dist(vi,vj)Dist(v_i, v_j) over 1i,jk1 \le i, j \le k with iji \neq j .

When you have found aa and bb ( 1a,bn)1 \le a, b \le n) , aba\neq b ) such that Dist(a,b)Dist(a, b) is the maximum possible, print the answer in the following format:

! aa bb

Outputting answer doesn't count towards the limit of 1212 queries.

If there are several pairs (a,b)(a, b) with the same largest Dist(a,b)Dist(a, b) , you can output any.

After printing a query do not forget to output the end of 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 the documentation for other languages.

Hacks

To hack a solution, use the following format.

The first line should contain a single integer nn (2n103)(2 \leq n \le 10^3) — the number of nodes.

The ii -th of the next n1n-1 lines should contain three integers uiu_i , viv_i , wiw_i ( 1ui,vin1 \le u_i, v_i \le n , uiviu_i\ne v_i , 1w1091 \le w \le 10^9 ), which means that there's an edge between nodes uiu_i and viv_i with weight wiw_i .

These n1n-1 edges must form a tree.

输入输出样例

  • 输入#1

    6
    1 2
    2 3
    2 4
    1 5
    5 6
    
    10
    
    2
    
    10

    输出#1

    ? 6 1 2 3 4 5 6
    
    ? 3 3 1 5
    
    ? 2 1 2
    
    ! 1 2

说明/提示

The tree in the first sample:

首页