#P14784. [NERC 2025] Cacti Classification

    ID: 16611 远端评测题 3000ms 1024MiB 尝试: 0 已通过: 0 难度: 9 上传者: 标签>2025交互题Special JudgeICPCNERC/NEERC

[NERC 2025] Cacti Classification

题目描述

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?

输入格式

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

The first line of each test case contains mm (1m1041 \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.

Interaction Protocol

To ask a query, output a line in the following format (without the quotes):

  • ? p e (0pq0 \le p \le q; 1em1 \le e \le m), where pp is the number of a previous query or zero (queries are numbered from 11 in the order they are asked), qq is the number of queries made before the current one, ee is the label of an edge.

The query denotes a graph consisting of the edges used in the query number pp (or all edges if p=0p = 0), with edge ee removed. The interactor checks whether this graph is connected when considering all original vertices and returns a single integer:

  • 11 if the graph denoted by the query is connected;
  • 00 if the graph denoted by the query is not connected;
  • 1-1 if you have exceeded 8m8m allowed queries or edge ee was already removed from the set of edges used in query pp. In this case you should terminate your program to receive a Wrong Answer verdict.

When you have found the answer, output a single line in the following format:

  • ! e_1 e_2 … e_m (1ei14-1 \le e_i \le 14 for all ii),

where:

  • if eie_i is positive, then edge number ii belongs to a simple cycle of length exactly eie_i;
  • if ei=0e_i = 0, then edge number ii belongs to a big cycle (simple cycle of length greater than 1414);
  • if ei=1e_i = -1, then edge number ii does not belong to any cycle.

The interactor returns a single integer:

  • 11 if your answer is correct. Proceed to the next test case or terminate your program if this was the last case.
  • 1-1 if your answer is incorrect. In this case you should terminate your program to receive a Wrong Answer verdict.

The interactor is not adaptive, meaning that the graph is fixed before you ask any queries.

1
7

0

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).

:::align{center} :::