logo AlgoBeat OnlineJudge
登录 注册

#214293. [ICPC 2024 Hangzhou R] Identify Chord

内存限制:1024 MiB 时间限制:1000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

Grammy has an undirected cyclic graph of () vertices numbered from to . An undirected cyclic graph is a graph of vertices and undirected edges that form one cycle. Specifically, there is a bidirectional edge between vertex and vertex for each .

Grammy thinks that this graph is too boring, so she secretly chooses a pair of vertices and connects an undirected edge (called a chord) between them, so that the graph now contains vertices and edges.

Your task is to guess the position of the chord by making no more than queries. Each query consists of two vertices and , and Grammy will tell you the number of edges on the shortest path between the two vertices.

Note that the interactor is , meaning that the position of the chord is pre-determined.

输入格式

There are multiple test cases. The first line of the input contains an integer () indicating the number of test cases. For each test case:

The first line contains an integer () indicating the number of vertices.

输出格式

To ask a query, output one line. First output \texttt{?} followed by a space, then output two vertices and () separated by a space. After flushing your output, your program should read a single integer indicating the number of edges on the shortest path between the two vertices.

To guess the position of the chord, output one line. First output followed by a space, then output two vertices and () separated by a space, indicating that the chord connects vertices and . After flushing your output, your program should read a single integer () indicating the correctness of your guess. If then your guess is correct, and your program should continue processing the next test case, or exit immediately if there are no more test cases. Otherwise if then your guess is incorrect, and your program should exit immediately to receive a verdict. Note that your guess does not count as a query.

To flush your output, you may use:

  • (if you use ) or (if you use ) in C and C++.
  • in Java.
  • in Python.

样例

样例输入 1

2
6

2

1

1
4

2

1

样例输出 1



? 1 5

? 2 4

! 4 2


? 2 4

! 1 3

数据范围与提示

The graphs in the sample test cases are illustrated as follows:

:::align{center} :::