Connectivity

아직 제출이 없습니다시간 제한10초메모리 제한512 MB

문제

This is an interactive problem.

The jury made a random undirected graph of nn vertices and mm edges with no loops or parallel edges. In each test, the graph is randomly uniformly sampled from all possible graphs with fixed nn and mm before the testing of your program starts.

Your program has to determine whether the graph is connected, while knowing only nn and mm at first. The program can perform a "? ii" query (1in1 \le i \le n) at most 2n2 \cdot n times. In response for such query, the testing system will give either:

  • Positive integer jj (1jn1 \le j \le n) meaning that there is an edge between vertices ii and jj and that the edge was not previously communicated to the program (including any responses to "? jj" queries).
  • Number 1-1 meaning that all edges adjacent to the vertex ii were already communicated to the program.

힌트

Empty lines are added for clarity, they are absent during interaction.

In the example test, the two following graphs are used. The testing system responds to "? ii" with the first edge in the list which is adjacent to ii and was not yet communicated to the program.

  1. n=5n = 5, m=4m = 4, edges are ordered as follows: 1--2, 1--4, 3--4, 1--5.
  2. n=5n = 5, m=4m = 4, edges are ordered as follows: 1--4, 1--3, 1--2, 3--4.