CF BUDDY
← Problems·

1592D · Hemose in ICPC ?

2300 · binary search, dfs and similar, implementation

Problem: 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?

Note: The tree in the first sample:

Sample Cases

Case 1

Input

6
1 2
2 3
2 4
1 5
5 6

10

2

10

Output

? 6 1 2 3 4 5 6

? 3 3 1 5

? 2 1 2

! 1 2

Similar problems

00:00:00
Loading editor…
Welcome! I'm your coding tutor for this problem. Use the chips below to reveal stored hints or get AI feedback on your code. I'll guide you step by step — never giving away the solution.

Sign in to unlock AI tutor feedback