Independent Set

시간 제한1초메모리 제한2048 MB

요약
정점 수열을 넣으면 각 정점마다 독립 집합에 이미 들어간 이웃의 수를 돌려주는 오라클을 이용해, 알려지지 않은 다중 그래프의 모든 간선을 찾아낸다.
난이도

어려움10점 중 9점

유형
그래프, 분할 정복, 구현, 완전 탐색
정답자
아직 제출이 없습니다

문제

This is an interactive problem. You have to use the flush operation right after printing each line. For example, you can use the function fflush(stdout) for C or C++, System.out.flush() for Java, flush(output) for Pascal, and sys.stdout.flush() for Python.

An independent set in a graph is a set of vertices such that, for every two vertices in the set, there is no edge connecting them.

There is an algorithm to construct an independent set in the graph.

The algorithm receives a sequence of vertices. Suppose the sequence is a_1,a_2,…,a_ℓa\_1, a\_2, \ldots, a\_{\ell}. Initially, there is an empty set SS and a sequence cnt_1,cnt_2,…,cnt_ℓ\mathit{cnt}\_1, \mathit{cnt}\_2, \ldots, \mathit{cnt}\_{\ell} that satisfies cnt_1=cnt_2=…=cnt_ℓ=0\mathit{cnt}\_1 = \mathit{cnt}\_2 = \ldots = \mathit{cnt}\_{\ell} = 0.

Then for ii from 11 to ℓ\ell:

  • Look at every edge in the graph, and increment cnt_i=cnt_i+1\mathit{cnt}\_i = \mathit{cnt}\_i + 1 every time when the edge connects a_ia\_i and a vertex in SS.
  • If cnt_i=0\mathit{cnt}\_i = 0 after searching, insert a_ia\_i into SS.

Obviously, SS will be an independent set after the algorithm.

Now, you only know the number of vertices nn in the graph, and you want to find all its edges. There is an interactor to help you. The interactor receives a sequence of vertices, runs the algorithm above, and returns the sequence cnt_1,cnt_2,…,cnt_ℓ\mathit{cnt}\_1, \mathit{cnt}\_2, \ldots, \mathit{cnt}\_{\ell}.

You want to achieve your goal with the total length of the sequences that you feed no more than 176,000176\\,000.

Note that there may be multiple edges and self-loops in the graph.

입력

The first line contains a single integer nn, the number of vertices in the graph.

Suppose mm is the number of edges in the graph. It is guaranteed that 1≤n≤40001 \leq n \leq 4000 and 0≤m≤10,0000 \leq m \leq 10\\,000.

예제1

  1. 예제 1

    입력
    4
    
    0 2 1 0 1 0
    
    0 1 1 0 0
    
    
    예상 출력
    
    ? 6 1 2 3 1 3 4
    
    ? 5 4 4 4 2 3
    
    ! 4 1 2 1 2 1 3 4 4