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 n nodes and n−1 edges. Unfortunately, Hemose doesn't remember the weights of edges.
Let's define Dist(u,v) for u=v as the greatest common divisor of the weights of all edges on the path from node u to node v .
Hemose has a special device. Hemose can give the device a set of nodes, and the device will return the largest Dist between any two nodes from the set. More formally, if Hemose gives the device a set S of nodes, the device will return the largest value of Dist(u,v) over all pairs (u,v) with u , v ∈ S and u=v .
Hemose can use this Device at most 12 times, and wants to find any two distinct nodes a , b , such that Dist(a,b) is maximum possible. Can you help him?
输入格式
无
输出格式
Begin the interaction from reading a single integer n ( 2≤n≤103 ) — the number of nodes in the tree.
Next, read n−1 lines.
The i -th of the next n−1 lines contains two integers ui and vi ( 1≤ui,vi≤n , ui=vi ), which means that there's an edge between nodes ui and vi .
It's guaranteed that weights of edges were ≤109 .
It is guaranteed that the given graph is a tree.
Now you may begin asking queries. To ask a query about a set of k nodes v1,v2,…,vk ( 2≤k≤n , 1≤vi≤n , all vi are distinct), output:
? k v1 v2 … vk
You will then receive an integer x , the largest Dist(vi,vj) over 1≤i,j≤k with i=j .
When you have found a and b ( 1≤a,b≤n) , a=b ) such that Dist(a,b) is the maximum possible, print the answer in the following format:
! a b
Outputting answer doesn't count towards the limit of 12 queries.
If there are several pairs (a,b) with the same largest 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 n (2≤n≤103) — the number of nodes.
The i -th of the next n−1 lines should contain three integers ui , vi , wi ( 1≤ui,vi≤n , ui=vi , 1≤w≤109 ), which means that there's an edge between nodes ui and vi with weight wi .
These n−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: