CF1534D.Lost Tree

普及+/提高

通过率:0%

时间限制:3.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

This is an interactive problem.

Little Dormi was faced with an awkward problem at the carnival: he has to guess the edges of an unweighted tree of nn nodes! The nodes of the tree are numbered from 11 to nn.

The game master only allows him to ask one type of question:

  • Little Dormi picks a node rr (1≤r≤n1 \le r \le n), and the game master will reply with an array d1,d2,…,dnd_1, d_2, \ldots, d_n, where did_i is the length of the shortest path from node rr to ii, for all 1≤i≤n1 \le i \le n.

Additionally, to make the game unfair challenge Little Dormi the game master will allow at most ⌈n2⌉\lceil\frac{n}{2}\rceil questions, where ⌈x⌉\lceil x \rceil denotes the smallest integer greater than or equal to xx.

Faced with the stomach-churning possibility of not being able to guess the tree, Little Dormi needs your help to devise a winning strategy!

Note that the game master creates the tree before the game starts, and does not change it during the game.

这是一个交互式问题。

小 Dormi 在嘉年华上遇到了一个棘手的问题:他必须猜出一棵包含 nn 个节点的无权树的所有边!这棵树的节点编号为 11 到 nn。

游戏主持人只允许他提出一种类型的问题:

  • 小 Dormi 选择一个节点 rr(1≤r≤n1 \le r \le n),主持人将回复一个数组 d1,d2,…,dnd_1, d_2, \ldots, d_n,其中 did_i 表示从节点 rr 到节点 ii 的最短路径长度(对所有 1≤i≤n1 \le i \le n)。

此外,为了让游戏更具挑战性(且显得不太公平),主持人最多只允许提出 ⌈n2⌉\lceil\frac{n}{2}\rceil 个问题,其中 ⌈x⌉\lceil x \rceil 表示不小于 xx 的最小整数。

面对可能无法猜出这棵树的令人反胃的窘境,小 Dormi 需要你的帮助来设计一个必胜策略!

注意:主持人在游戏开始前就已构造好这棵树,并在整个游戏过程中保持不变。

输入格式

The first line of input contains the integer nn (2≤n≤2 0002 \le n \le 2\,000), the number of nodes in the tree.

You will then begin interaction.

输入的第一行包含整数 nn(2≤n≤2 0002 \le n \le 2\,000),表示树中节点的数量。

随后你将开始交互。

输出格式

When your program has found the tree, first output a line consisting of a single "!" followed by n−1n-1 lines each with two space separated integers aa and bb, denoting an edge connecting nodes aa and bb (1≤a,b≤n1 \le a, b \le n). Once you are done, terminate your program normally immediately after flushing the output stream.

You may output the edges in any order and an edge (a,b)(a,b) is considered the same as an edge (b,a)(b,a). Answering is not considered as a query.

当你的程序找到该树后,首先输出一行,仅包含一个“!”;然后输出 n−1n-1 行,每行包含两个以空格分隔的整数 aa 和 bb,表示连接节点 aa 和 bb 的一条边(1≤a,b≤n1 \le a, b \le n)。完成输出后,请立即正常终止程序,并在终止前刷新输出流。

你可以以任意顺序输出各条边;边 (a,b)(a,b) 与边 (b,a)(b,a) 被视为同一条边。提交答案本身不被视为一次查询。

输入输出样例

  • 输入#1

    4
    
    0 1 2 2
    
    1 0 1 1

    输出#1

    ? 1
    
    ? 2
    
    !
    4 2
    1 2
    2 3
  • 输入#2

    5
    
    2 2 1 1 0

    输出#2

    ? 5
    
    !
    4 5
    3 5
    2 4
    1 3

说明/提示

Here is the tree from the first example.

Notice that the edges can be output in any order.

Additionally, here are the answers for querying every single node in example 11:

  • 11: [0,1,2,2][0,1,2,2]
  • 22: [1,0,1,1][1,0,1,1]
  • 33: [2,1,0,2][2,1,0,2]
  • 44: [2,1,2,0][2,1,2,0]

Below is the tree from the second example interaction.

Lastly, here are the answers for querying every single node in example 22:

  • 11: [0,4,1,3,2][0,4,1,3,2]
  • 22: [4,0,3,1,2][4,0,3,1,2]
  • 33: [1,3,0,2,1][1,3,0,2,1]
  • 44: [3,1,2,0,1][3,1,2,0,1]
  • 55: [2,2,1,1,0][2,2,1,1,0]

以下是第一个示例中的树。

注意:边的输出顺序可以是任意的。

此外,以下是在示例 11 中对每个节点分别进行查询所得到的答案:

  • 11: [0,1,2,2][0,1,2,2]
  • 22: [1,0,1,1][1,0,1,1]
  • 33: [2,1,0,2][2,1,0,2]
  • 44: [2,1,2,0][2,1,2,0]

以下是第二个示例交互中的树。

最后,以下是在示例 22 中对每个节点分别进行查询所得到的答案:

  • 11: [0,4,1,3,2][0,4,1,3,2]
  • 22: [4,0,3,1,2][4,0,3,1,2]
  • 33: [1,3,0,2,1][1,3,0,2,1]
  • 44: [3,1,2,0,1][3,1,2,0,1]
  • 55: [2,2,1,1,0][2,2,1,1,0]

输入解题思路,AI测评打分。不知道怎么写?

首页