Space Thief

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

요약
연결된 무향 그래프에서 각 간선의 방향을 정해 도달 가능성을 묻는 질문을 300번 이내로 던져, 열쇠가 숨겨진 별 A와 보물 상자가 숨겨진 별 B를 알아낸다.
난이도

어려움10점 중 9점

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

문제

You are active as a thief in JOI galaxy.

There are NN stars numbered from 00 to N−1N - 1 in JOI galaxy. There are MM warp devices numbered from 00 to M−1M -1 in JOI galaxy. The warp device ii (0≤i≤M−10 ≤ i ≤ M -1) connects star U_iU\_i and star V_iV\_i bidirectionally. It is possible to travel from any star to any star by using warp devices.

A key is hidden in a certain star, and a treasure box is hidden in another certain star. Your mission is to specify numbers, the number of the star in which the key is hidden and in which the treasure box is hidden. To achieve your mission, you can ask questions up to 300300 times as below.

  • Orient each warp device. Specifically, for each warp device ii (0≤i≤M−10 ≤ i ≤ M - 1), choose one of the following:

    • Allow travel only from star U_iU\_i to star V_iV\_i.
    • Allow travel only from star V_iV\_i to star U_iU\_i.
  • Under these conditions, ask whether it is possible to travel from the star in which the key is hidden to the star in which the treasure box is hidden by using warp devices.

You want to specify numbers, the number of the star AA in which the key is hidden and the star BB in which the treasure box is hidden. To achieve a higher evaluation, you want to reduce the number of questions asked.

Given information about the galaxy, write a program that determines the star AA in which the key is hidden and the star BB in which the treasure box is hidden, by asking questions.

제한

All the input data satisfy the following conditions.

  • 2≤N≤10,0002 ≤ N ≤ 10\\, 000.
  • 1≤M≤15,0001 ≤ M ≤ 15\\, 000.
  • 0≤A≤N−10 ≤ A ≤ N - 1.
  • 0≤B≤N−10 ≤ B ≤ N - 1.
  • A≠BA \ne B.
  • 0≤U_i<V_i≤N−10 ≤ U\_i < V\_i ≤ N - 1 (0≤i≤M−10 ≤ i ≤ M - 1).
  • (U_i,V_i)≠(U_j,V_j)(U\_i , V\_i) \ne (U\_j , V\_j) (0≤i<j≤M−10 ≤ i < j ≤ M - 1).
  • It is possible to travel from any star to any star by using warp devices.

예제

이 문제는 공개된 예제가 없습니다.