308892: CF1592D. Hemose in ICPC ?
Memory Limit:256 MB
Time Limit:1 S
Judge Style:Text Compare
Creator:
Submit:0
Solved:0
Description
Hemose in ICPC ?
题意翻译
CF 文件交互题 给一棵 $n$ 个点的树,定义 $Dist(u,v)$ 为 $u \to v$ 路径上的边构成的边权集合的 $\gcd$,且 $u \neq v$。 每一你可以询问交互库 $x$ 个点的点集 $X$,交互库会返回 $X$ 中,$\max\{Dist(u,v)\}, u,v \in X$ 。也就是说,交互库会找到 $X$ 中 $Dist$ 最大的一个点对 $(u,v)$ 并且返回它们的 $Dist$。 最多可以询问交互库 $12$ 次。你需要找到整棵树中 $Dist(u,v)$ 最大的那个点对 $(u,v)$。若有多个,任意一个都合法。 交互格式: 询问:`? k v_1 v_2 ... v_k` 回答:`! u v` Translated by [Tony102](https://tony102.com)题目描述
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?输入输出格式
输入格式
输出格式
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.
输入输出样例
输入样例 #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