Codeforces Round 746 (Div. 2)
D
Hemose in ICPC ?
Codeforces
2300
原题
← CE →
翻译中…

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\neq 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$ $\in$ $S$ and $u \neq 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?

翻译中…

Interaction

翻译中…

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

翻译中…

Next, read $n-1$ lines.

翻译中…

The $i$-th of the next $n-1$ lines contains two integers $u_i$ and $v_i$ ($1 \leq u_i, v_i \leq n$, $u_i\neq v_i$), which means that there's an edge between nodes $u_i$ and $v_i$.

翻译中…

It's guaranteed that weights of edges were $\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 $k$ nodes $v_1, v_2, \ldots, v_k$ ($2 \le k \le n$, $1 \le v_i \le n$, all $v_i$ are distinct), output:

翻译中…

? $k$ $v_1$ $v_2$ $\ldots$ $v_k$

翻译中…

You will then receive an integer $x$, the largest $Dist(v_i, v_j)$ over $1 \le i, j \le k$ with $i \neq j$.

翻译中…

When you have found $a$ and $b$ ($1 \le a, b \le n)$, $a\neq 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 \leq n \le 10^3)$ — the number of nodes.

翻译中…

The $i$-th of the next $n-1$ lines should contain three integers $u_i$, $v_i$, $w_i$ ($1 \le u_i, v_i \le n$, $u_i\ne v_i$, $1 \le w \le 10^9$), which means that there's an edge between nodes $u_i$ and $v_i$ with weight $w_i$.

翻译中…

These $n-1$ edges must form a tree.

翻译中…

Note

翻译中…

The tree in the first sample:

翻译中…

image

翻译中…

样例

Input #1
6
1 2
2 3
2 4
1 5
5 6

10

2

10
Output #1
? 6 1 2 3 4 5 6

? 3 3 1 5

? 2 1 2

! 1 2
InputCopy OutputCopy
题目信息
题号
1592D
时间限制
1 s
内存限制
256 MB
标签
二分
DFS 及类似
模拟
交互题
数学
数论
树

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。