#1370
Diamond IV
Cactus Search
인터랙티브
시간 제한
4s
메모리 제한
512MB
제출
1
정답
1
맞힌 사람
1
정답 비율
100.0%

문제

If you want to make an array problem harder — solve it on a tree. If you want to make a tree problem harder — solve it on a cactus — Conventional wisdom

NEERC featured a number of problems in previous years about cactuses — connected undirected graphs in which every edge belongs to at most one simple cycle. Intuitively, a cactus is a generalization of a tree where some cycles are allowed. An example of a cactus from NEERC 2007 problem is given on the picture below.

You are playing a game on a cactus with Chloe. You are given a cactus. Chloe had secretly picked one vertex vv from the cactus and your goal is to find it. You can make at most 10 guesses. If your guess is vertex vv — you win. Otherwise, if your guess is another vertex uu — Chloe helps you and tells you some vertex ww which is adjacent to uu and such that the distance from ww to vv is strictly less than the distance from uu to vv (here the distance is the number of edges in the shortest path between vertices).

상호작용

First, the testing system writes a line with two integers nn and mm (1n500;0m500)(1 \le n \le 500; 0 \le m \le 500). Here nn is the number of vertices in the graph. Vertices are numbered from 1 to nn. Edges of the graph are represented by a set of edge-distinct paths, where mm is the number of such paths. Each of the following mm lines contains a path in the graph. A path starts with an integer kik_i (2ki500)(2 \le k_i \le 500) followed by kik_i integers from 1 to nn. These kik_i integers represent vertices of a path. Adjacent vertices in a path are distinct. The path can go to the same vertex multiple times, but every edge is traversed exactly once in the whole input. The graph in the input is a cactus.

To prove that your program can find a secret vertex in at most 10 queries, you need to do that nn times. Each time testing system picks some vertex before interacting with your program. Your program makes guesses by writing lines with a single number uu (1un1 \le u \le n).

Testing system responds by writing lines with one of the two responses:

  • "FOUND" — means that your guess is correct. After that, your program should proceed to the next test case or terminate if nn vertices were already guessed.
  • "GO ww" — means that your guess is incorrect, but now you know that the distance from vertex ww to the secret vertex is less than the distance from uu. It is guaranteed that vertices uu and ww are connected by an edge.

Do not forget to flush the output after each guess!

예제 입력 1

5 2
5 1 2 3 4 5
2 1 3

FOUND

GO 4

FOUND

GO 2

FOUND

GO 1

FOUND

GO 4

GO 5

FOUND

예제 출력 1

 


3

3

4

3

2

3

1

3

4

5

노트

Empty lines are added to the standard input and the standard output examples for clarity only. They are not present during the actual interaction.

코드 제출

코드를 제출하려면 로그인이 필요합니다.

로그인
내 제출
제출 내역이 없습니다.
맞은 사람
#순위사용자언어시간메모리코드 길이
8714🥇
조서현
C++146ms17912KB2409B
난이도 투표
Diamond IV1명 투표· 4일 전
로그인 후 AC 받으면 투표할 수 있습니다.
전체 제출
#사용자문제결과언어시간메모리코드 길이제출 시간
8714
맞았습니다
C++146ms17912KB2409B2026. 06. 02. 07:15