아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Connectivity

면접 대비

시간 제한10초메모리 제한512 MB

요약
무작위 무방향 그래프의 n과 m만 주어진 상태에서 정점을 최대 2n번 질의해 아직 공개되지 않은 인접 간선을 받아 그래프의 연결 여부를 판정한다.
난이도

보통10점 중 6점

유형
그래프, BFS, 확률, 그리디
정답자
아직 제출이 없습니다

문제

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 (1≤i≤n1 \le i \le n) at most 2⋅n2 \cdot n times. In response for such query, the testing system will give either:

  • Positive integer jj (1≤j≤n1 \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.

예제1

  1. 예제 1

    입력
    2
    5 4
    
    2
    
    1
    
    5
    
    -1
    
    3
    
    -1
    
    5 4
    
    -1
    
    
    예상 출력
    
    ? 1
    
    ? 4
    
    ? 1
    
    ? 1
    
    ? 4
    
    ? 4
    
    +
    
    ? 5
    
    -