CF2245G.NPC Challenge

NOI/NOI+/CTSC

通过率:0%

时间限制:4.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

This is an interactive problem.

There is a hidden undirected tree consisting of nn vertices. To find this tree, you may ask queries of the following form:

  • Pick a sequence of distinct vertices a1,a2,…,aka_1, a_2, \ldots, a_k, where k≥1k \ge 1.

The interactor will process your sequence and return a subset of these vertices, denoted by SS. The set SS is generated by the following process:

  • Initially, SS is an empty set.

  • The interactor processes the vertices in the exact order they appear in your sequence, from a1a_1 to aka_k.

  • For each aia_i, if aia_i does not share an edge with any vertex that is currently in SS, then aia_i is added to SS. Otherwise, aia_i is ignored.

  • After processing all kk vertices, the interactor returns the final set SS to you. SS is represented by a binary string ss of length kk, where si=1s_i=\texttt{1} if and only if ai∈Sa_i \in S.

Your task is to find all n−1n-1 edges of the hidden tree. To make the problem harder, the sum of kk over all queries must not exceed 30⋅n30 \cdot n.

这是一个交互式问题。

存在一棵隐藏的、包含 nn 个顶点的无向树。为了找出这棵树,你可以提出如下形式的查询:

  • 选取一个由互不相同的顶点组成的序列 a1,a2,…,aka_1, a_2, \ldots, a_k,其中 k≥1k \ge 1。

交互器将处理你提供的序列,并返回该序列的一个子集 SS。集合 SS 的生成过程如下:

  • 初始时,SS 为空集。

  • 交互器严格按照你在序列中给出的顺序(即从 a1a_1 到 aka_k)依次处理各顶点。

  • 对每个 aia_i,若 aia_i 与当前 SS 中任意顶点均无边相连,则将 aia_i 加入 SS;否则忽略 aia_i。

  • 在处理完全部 kk 个顶点后,交互器将最终得到的集合 SS 返回给你。SS 以长度为 kk 的二进制字符串 ss 表示,其中当且仅当 ai∈Sa_i \in S 时,si=1s_i = \texttt{1}。

你的任务是找出隐藏树的全部 n−1n-1 条边。为增加难度,所有查询中 kk 值的总和不得超过 30⋅n30 \cdot n。

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤1001 \le t \le 100). The description of the test cases follows.

The first line of each test case contains an integer nn (2≤n≤1032 \le n \le 10^3), representing the number of vertices in the hidden tree.

It is guaranteed that the sum of nn over all test cases does not exceed 10310^3.

每个测试包含多个测试用例。第一行包含测试用例的数量 tt(1≤t≤1001 \le t \le 100)。随后是各测试用例的描述。

每个测试用例的第一行包含一个整数 nn(2≤n≤1032 \le n \le 10^3),表示隐藏树中的顶点数量。

保证所有测试用例的 nn 值之和不超过 10310^3。

输出格式

null

输入输出样例

  • 输入#1

    2
    2
    
    10
    
    
    5
    
    101
    
    10101

    输出#1

    ? 2 1 2
    
    !
    2 1
    
    ? 3 1 2 5
    
    ? 5 5 3 4 2 1
    
    !
    3 5
    1 2
    3 2
    2 4

说明/提示

In the first test case, the hidden tree consists of n=2n=2 vertices, and the only edge is (1,2)(1,2).

  • For the first query, a=[1,2]a=[1,2]:

    • Vertex 11 is processed. Currently, SS is empty. Since 11 has no neighbors in SS, it is added to SS. SS becomes 1{1}.

    • Vertex 22 is processed. Its neighbor, vertex 11, is already in SS. Thus, vertex 22 is ignored.

In the second test case, the hidden tree consists of n=5n=5 vertices. The edges are (1,2)(1, 2), (2,3)(2, 3), (2,4)(2, 4), and (3,5)(3, 5).

  • For the first query, a=[1,2,5]a=[1,2,5]:

    • Vertex 11 is processed. SS is empty. It is added to SS. SS becomes 1{1}.

    • Vertex 22 is processed. It shares an edge with vertex 1∈S1 \in S. It is ignored.

    • Vertex 55 is processed. Its only neighbor is vertex 3∉S3 \notin S. It is added to SS. SS becomes 1,5{1, 5}.

  • For the second query, a=[5,3,4,2,1]a=[5,3,4,2,1]:

    • Vertex 55 is processed. SS is empty. It is added to SS. SS becomes 5{5}.

    • Vertex 33 is processed. It shares an edge with vertex 5∈S5 \in S. It is ignored.

    • Vertex 44 is processed. Its only neighbor is vertex 2∉S2 \notin S. It is added to SS. SS becomes 4,5{4, 5}.

    • Vertex 22 is processed. It shares an edge with vertex 4∈S4 \in S. It is ignored.

    • Vertex 11 is processed. Its only neighbor is vertex 2∉S2 \notin S. Since it has no neighbors in SS, it is added to SS.

在第一个测试用例中,隐藏的树包含 n=2n=2 个顶点,且唯一的一条边为 (1,2)(1,2)。

  • 对于第一次查询,a=[1,2]a=[1,2]:

    • 处理顶点 11。此时 SS 为空。由于 11 在 SS 中没有邻居,因此将其加入 SS。SS 变为 {1}\{1\}。

    • 处理顶点 22。其邻居顶点 11 已在 SS 中。因此忽略顶点 22。

在第二个测试用例中,隐藏的树包含 n=5n=5 个顶点。边集为 (1,2)(1, 2)、(2,3)(2, 3)、(2,4)(2, 4) 和 (3,5)(3, 5)。

  • 对于第一次查询,a=[1,2,5]a=[1,2,5]:

    • 处理顶点 11。SS 为空。将其加入 SS。SS 变为 {1}\{1\}。

    • 处理顶点 22。它与 SS 中的顶点 11 相邻。因此忽略顶点 22。

    • 处理顶点 55。它的唯一邻居是顶点 33,而 3∉S3 \notin S。因此将其加入 SS。SS 变为 {1,5}\{1, 5\}。

  • 对于第二次查询,a=[5,3,4,2,1]a=[5,3,4,2,1]:

    • 处理顶点 55。SS 为空。将其加入 SS。SS 变为 {5}\{5\}。

    • 处理顶点 33。它与 SS 中的顶点 55 相邻。因此忽略顶点 33。

    • 处理顶点 44。它的唯一邻居是顶点 22,而 2∉S2 \notin S。因此将其加入 SS。SS 变为 {4,5}\{4, 5\}。

    • 处理顶点 22。它与 SS 中的顶点 44 相邻。因此忽略顶点 22。

    • 处理顶点 11。它的唯一邻居是顶点 22,而 2∉S2 \notin S。由于它在 SS 中没有邻居,因此将其加入 SS。

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

首页