CF2181C.Cacti Classification

NOI/NOI+/CTSC

通过率:0%

时间限制:3.00s

内存限制:1024MB

AC君温馨提醒

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

题目描述

Ivan and Petr like to play with cacti — special graphs where each edge belongs to at most one simple cycle, and the graph is connected. Multiple edges between pairs of vertices and loops are allowed.

They invent the following game:

  • Petr secretly builds a cactus with nn vertices and mm edges. The edges are labeled from 11 to mm.
  • Petr only tells Ivan the number mm.
  • Ivan is then allowed to ask questions of the following form:
    • He chooses a subset SS of edge labels (see below about limitations on the subset), and asks: "If we only keep the edges whose labels are in SS (and all nn vertices), is the resulting graph connected?"
    • Petr must answer either "yes" or "no".

After asking at most 8m8m questions, Ivan must determine, for every edge:

  1. whether this edge lies on some cycle in the cactus;
  2. if it does, what is the length of that simple cycle.

In this problem, each loop is considered a simple cycle of length 11 and two edges between the same pair of vertices form a simple cycle of length 22.

However, Ivan is still very young and only knows numbers up to 1414. So:

  • if an edge lies on a simple cycle of length at most 1414, he must output that exact length;
  • if an edge lies on a simple cycle of length greater than 1414, he must say that this edge lies on a big cycle.

Also, to avoid having to list a lot of edges each time, Ivan always asks about an edge set obtained from the set used in one of the previous queries, or from the set of all edges, by removing exactly one edge.

Can you design a strategy that allows Ivan to complete this task?

伊万和彼得喜欢玩仙人掌图——一种特殊的图,其中每条边至多属于一个简单环,且整个图是连通的。允许在顶点对之间存在多重边,也允许存在自环。

他们设计了如下游戏:

  • 彼得秘密构造一棵具有 nn 个顶点和 mm 条边的仙人掌图。这些边被依次标记为 11 到 mm。
  • 彼得仅将数字 mm 告知伊万。
  • 随后,伊万可以提出以下形式的问题(关于子集 SS 的限制见下文):
    • 他选择一个边标签的子集 SS,并提问:“若仅保留标签属于 SS 的边(以及全部 nn 个顶点),所得图是否连通?”
    • 彼得必须回答“是”或“否”。

在最多提出 8m8m 个问题之后,伊万必须对每一条边确定:

  1. 该边是否位于仙人掌图的某个简单环上;
  2. 若是,则该简单环的长度是多少。

本题中,每个自环被视为长度为 11 的简单环;连接同一对顶点的两条边构成长度为 22 的简单环。

然而,伊万年纪尚小,只会处理不超过 1414 的数字。因此:

  • 若某条边位于长度不超过 1414 的简单环上,则他必须输出该精确长度;
  • 若某条边位于长度大于 1414 的简单环上,则他必须声明该边位于一个“大环”上。

此外,为避免每次均需列举大量边,伊万所询问的边集总是由前一次查询所用的边集、或由全体边集,通过恰好移除一条边而得到。

你能否设计一种策略,使伊万能完成此项任务?

输入格式

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 mm (1≤m≤1041 \le m \le 10^4) — the number of edges in the cactus.

It is guaranteed that the sum of mm over all test cases does not exceed 10410^4.

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

每个测试用例的第一行包含 mm(1≤m≤1041 \le m \le 10^4)——即仙人掌图中的边数。

保证所有测试用例的 mm 值之和不超过 10410^4。

输入输出样例

  • 输入#1

    1
    7
    
    0
    
    1
    
    1
    
    1

    输出#1

    ? 0 1
    
    ? 0 3
    
    ? 2 4
    
    ! -1 3 1 3 2 3 2

说明/提示

In the example interaction, the input and output contain empty lines to align interactor responses with queries. These empty lines do not appear in the actual input and output.

In this example, the graph has 55 vertices and 77 edges; edges 11 through 77, in this order, are (1,2)(1, 2), (2,3)(2, 3), (3,3)(3, 3), (3,4)(3, 4), (4,5)(4, 5), (2,4)(2, 4), (4,5)(4, 5).

在示例交互中,输入和输出包含空行,以使交互器(interactor)的响应与查询对齐。这些空行不会实际出现在输入和输出中。

在本例中,图包含 55 个顶点和 77 条边;按顺序编号为 11 至 77 的边分别为 (1,2)(1, 2)、(2,3)(2, 3)、(3,3)(3, 3)、(3,4)(3, 4)、(4,5)(4, 5)、(2,4)(2, 4)、(4,5)(4, 5)。

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

首页