아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Game on Tree

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

요약
한 명은 리프를 하나씩 표시하고 다른 한 명은 루트에서 칩을 움직이며, 누가 이기는지 판정하고 표시하는 쪽이 이길 경우 첫 수 리프를 출력한다.
난이도

보통10점 중 6점

유형
트리, 그리디, 게임 이론
정답자
아직 제출이 없습니다

문제

You are given an undirected rooted tree. Vertices are numbered with integers from 11 to nn. The root is vertex 11.

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 11, 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 nn: the number of vertices in the tree (2≤n≤100,0002 \le n \le 100\\,000). The second line contains n−1n - 1 integers p_2,p_3,…,p_np\_2, p\_3, \ldots, p\_n. Here, p_ip\_i is the parent of vertex ii (1≤p_i<i1 \le p\_i < i).

출력

If the first player wins, print "FIRST" on the first line. After that, on the second line, print an integer vv (2≤v≤n2 \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.

예제2

  1. 예제 1

    입력
    2
    1
    
    예상 출력
    FIRST
    2
    
  2. 예제 2

    입력
    3
    1 1
    
    예상 출력
    SECOND