Codeforces Round 682 (Div. 2)
F
Olha and Igor
Codeforces
3000
原题
← E→
翻译中…

This is an interactive problem.

翻译中…

Igor wants to find the key to Olha's heart. The problem is, that it's at the root of a binary tree.

翻译中…

There is a perfect binary tree of height $h$ consisting of $n = 2^{h} - 1$ nodes. The nodes have been assigned distinct labels from $1$ to $n$. However, Igor only knows $h$ and does not know which label corresponds to which node.

翻译中…

To find key to Olha's heart he needs to find the label assigned to the root by making queries of the following type at most $n+420$ times:

翻译中…
  • Select three distinct labels $u$, $v$ and $w$ ($1 \leq u,v,w \leq n$).
  • In response, Olha (the grader) will tell him the label of the lowest common ancestor of nodes labelled $u$ and $v$, if the tree was rooted at the node labelled $w$ instead.
翻译中…

Help Igor to find the root!

翻译中…

Note: the grader is not adaptive: the labels are fixed before any queries are made.

翻译中…

Input

翻译中…

The first and only line contains a single integer $h$ ($3 \le h \le 18$) — the height of the tree.

翻译中…

Interaction

翻译中…

You begin the interaction by reading $h$.

翻译中…

To make a query for labels $u, v, w$, in a separate line output "? u v w".

翻译中…

Numbers in the query have to satisfy $1 \le u, v, w \le n$. Additionally, $u \ne v$, $u \ne w$, and $v \ne w$.

翻译中…

In response, you will receive $1 \le x \le n$, the label of the lowest common ancestor of $u$ and $v$, if the tree was rooted at $w$.

翻译中…

In case your query is invalid or you asked more than $n+420$ queries, program will print $-1$ and will finish interaction. You will receive Wrong answer verdict. Make sure to exit immediately to avoid getting other verdicts.

翻译中…

When you determine the label assigned to the root, output "! r", where $r$ is the label of the root.

翻译中…

After printing a query do not forget to output 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 documentation for other languages.
翻译中…

Hack Format

翻译中…

To hack, use the following format.

翻译中…

The first line should contain a single integer $h$ (height of the binary tree).

翻译中…

On the next line, output a permutation $p$ of size $n = 2^h - 1$. This represents a binary tree where the root is labelled $p_1$ and for $1 \lt i \le n$, the parent of $p_i$ is $p_{ \lfloor{\frac{i}{2}}\rfloor }$.

翻译中…

Note

翻译中…

The labels corresponding to the tree in the example are [$4$,$7$,$2$,$6$,$1$,$5$,$3$], meaning the root is labelled $4$, and for $1 \lt i \le n$, the parent of $p_i$ is $p_{ \lfloor{\frac{i}{2}}\rfloor }$.

翻译中…

样例

Input #1
3

2

7

4
Output #1
? 7 3 5

? 1 6 4

? 1 5 4

! 4
InputCopy OutputCopy
题目信息
题号
1438F
时间限制
4 s
内存限制
256 MB
标签
交互题
概率论
树

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