Finding Celebrities

시간 제한20초메모리 제한1024 MB

요약
A가 B를 아는지 묻는 질문을 Q번 이하로 사용해, 모든 사람이 알지만 아무도 모르는 유명인을 찾는다.
난이도

보통10점 중 6점

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

문제

This is an interactive problem.

It is time for the Sogang Computer Science Festival (Korean: 서강대학교 컴퓨터공학과 전산제). NN people gathered to congratulate the remarkable anniversary of the Department of Computer Science and Engineering.

There is a rumor that a celebrity has come to this festival. You, curious about who the celebrity is, are tasked with finding a celebrity among the NN people at this festival.

A celebrity is someone known by everyone at this festival who does not know anyone else. You can roam around the festival venue to ask if some person AA knows some other person BB. By asking at most QQ questions, determine whether this festival has a celebrity and, if so, identify who it is.

입력

Initially, two space-separated integers are given: NN, which denotes the number of attendees to this festival, and QQ, which denotes the number of questions you can ask. (1≤N≤100,000;1 \le N \le 100\\,000; See below for QQ)

출력

You can interact with the judging system by outputting one of the following:

  • ? AA BB: Ask if the person AA knows BB. (1≤A,B≤N;1 \le A,B \le N; A≠BA \ne B) This type of interaction can be made at most QQ times.
    • The judging system will answer 1 if the person AA knows BB, or 0 if they don't.
  • ! XX: If X≠−1X \ne -1, identify the celebrity as person XX. Otherwise, conclude that there is no celebrity in this festival.
    • Depending on your answer, the judging system will terminate your program and determine the verdict as either Accepted or Wrong Answer.

You should also output a newline character and flush the standard output buffer. Failure to adhere to any of these requirements can result in an unexpected verdict.

힌트

(For Sogang students:) Note that this problem is an improvised version that matches the format of a problem in a general programming contest. While in the exam, the original scoring was:

  • Around 7575 points for Subtask 1.
  • Around 2525 points for Subtask 2.

예제1

  1. 예제 1

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