#P14784. [NERC 2025] Cacti Classification
[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 vertices and edges. The edges are labeled from to .
- Petr only tells Ivan the number .
- Ivan is then allowed to ask questions of the following form:
- He chooses a subset of edge labels (see below about limitations on the subset), and asks: “If we only keep the edges whose labels are in (and all vertices), is the resulting graph connected?”
- Petr must answer either “yes” or “no”.
After asking at most questions, Ivan must determine, for every edge:
- whether this edge lies on some cycle in the cactus;
- if it does, what is the length of that simple cycle.
In this problem, each loop is considered a simple cycle of length and two edges between the same pair of vertices form a simple cycle of length .
However, Ivan is still very young and only knows numbers up to . So:
- if an edge lies on a simple cycle of length at most , he must output that exact length;
- if an edge lies on a simple cycle of length greater than , 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 (). The description of the test cases follows.
The first line of each test case contains () — the number of edges in the cactus.
It is guaranteed that the sum of over all test cases does not exceed .
Interaction Protocol
To ask a query, output a line in the following format (without the quotes):
? p e(; ), where is the number of a previous query or zero (queries are numbered from in the order they are asked), is the number of queries made before the current one, is the label of an edge.
The query denotes a graph consisting of the edges used in the query number (or all edges if ), with edge removed. The interactor checks whether this graph is connected when considering all original vertices and returns a single integer:
- if the graph denoted by the query is connected;
- if the graph denoted by the query is not connected;
- if you have exceeded allowed queries or edge was already removed from the set of edges used in query . 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( for all ),
where:
- if is positive, then edge number belongs to a simple cycle of length exactly ;
- if , then edge number belongs to a big cycle (simple cycle of length greater than );
- if , then edge number does not belong to any cycle.
The interactor returns a single integer:
- if your answer is correct. Proceed to the next test case or terminate your program if this was the last case.
- 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 vertices and edges; edges through , in this order, are , , , , , , .
:::align{center}
:::