Mysterious Tree

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

요약
꼭짓점 n개짜리 숨겨진 트리가 사슬인지 별인지 간선 질문을 ceil(n/2)+3번 이하로 던져 판별한다.
난이도

보통10점 중 7점

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

문제

This is an interactive problem.

Randias has an unknown hidden tree with nn vertices. The tree is either a chain or a star. Randias now needs to determine whether the tree is a chain or a star. He can ask a question in the following form, but no more than ⌈n2⌉+3\lceil \frac{n}{2} \rceil + 3 times:

  • Is there an edge between vertex uu and vertex vv (1≤u,v≤n1 \le u, v \le n, u≠vu \neq v)?

Randias needs to determine which of the two kinds the tree is. Help him to ask the questions and determine the answer.

A tree is called a chain if and only if there exists a permutation p_1,p_2,…,p_np\_{1}, p\_{2}, \ldots, p\_{n} such that, for every ii (1≤i<n1 \le i < n), there is an edge (p_i,p_i+1)(p\_{i}, p\_{i + 1}) in the tree. Here, a permutation of length nn is an array where each integer from 11 to nn appears exactly once.

A tree is called a star if and only if there exists a vertex uu such that, for every other vertex vv, there is an edge (u,v)(u, v) in the tree.

In this problem, the interactor is adaptive, which means that the secret tree is not fixed beforehand. Instead, the interactor can change the tree arbitrarily during the interaction. Nevertheless, at every moment, the tree will be consistent with all the answers you got.

입력

Each test contains multiple test cases. The first line contains a single integer tt (1≤t≤2501 \leq t \leq 250) denoting the number of test cases.

For each test case, the first line contains one integer nn (4≤n≤10004 \le n \le 1000) denoting the number of vertices. It is guaranteed that the sum of nn over all test cases does not exceed 10001000.

예제1

  1. 예제 1

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