Logo
(追記) (追記ここまで)

23655번 - Game on Tree 스페셜 저지다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 (추가 시간 없음) 256 MB239945.000%

문제

You are given an undirected rooted tree. Vertices are numbered with integers from 1ドル$ to $n$. The root is vertex 1ドル$.

Two players are playing a game on this tree. They make alternating moves.

The first player can mark one leaf on his move, and it will remain marked until the end of the game. A leaf of a rooted tree is a non-root vertex with only one neighbor. Initially, all leaves are unmarked.

The second player controls a chip. The chip is always located in some vertex. Initially, the chip is placed in vertex 1ドル,ドル the root of the tree. On his move, the second player can put the chip in any vertex adjacent to the current one, or leave it in the current vertex.

The game ends when either all leaves are marked (the first player wins) or the chip is put into some unmarked leaf (the second player wins). Who will be the winner if both players play optimally?

입력

The first line contains an integer $n$: the number of vertices in the tree (2ドル \le n \le 100,000円$). The second line contains $n - 1$ integers $p_2, p_3, \ldots, p_n$. Here, $p_i$ is the parent of vertex $i$ (1ドル \le p_i < i$).

출력

If the first player wins, print "FIRST" on the first line. After that, on the second line, print an integer $v$ (2ドル \le v \le n$): the number of vertex the first player has to mark on the first move. This vertex must be a leaf. The first player must win after this move if both play optimally. In case there are several such vertices, print any one of them.

If the second player wins, print "SECOND" on the first line.

제한

예제 입력 1

2
1

예제 출력 1

FIRST
2

예제 입력 2

3
1 1

예제 출력 2

SECOND

노트

출처

Contest > Open Cup > 2018/2019 Season > Stage 9: Grand Prix of Peterhof G번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /