Connectivity
면접 대비시간 제한10초메모리 제한512 MB
무작위 무방향 그래프의 n과 m만 주어진 상태에서 정점을 최대 2n번 질의해 아직 공개되지 않은 인접 간선을 받아 그래프의 연결 여부를 판정한다.
문제
This is an interactive problem.
The jury made a random undirected graph of vertices and edges with no loops or parallel edges. In each test, the graph is randomly uniformly sampled from all possible graphs with fixed and before the testing of your program starts.
Your program has to determine whether the graph is connected, while knowing only and at first. The program can perform a "? " query () at most times. In response for such query, the testing system will give either:
- Positive integer () meaning that there is an edge between vertices and and that the edge was not previously communicated to the program (including any responses to "
?" queries). - Number meaning that all edges adjacent to the vertex 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 "? " with the first edge in the list which is adjacent to and was not yet communicated to the program.
- , , edges are ordered as follows: 1--2, 1--4, 3--4, 1--5.
- , , edges are ordered as follows: 1--4, 1--3, 1--2, 3--4.