eolymp
bolt
Try our new interface for solving problems
Problems

Tree Games

Tree Games

\includegraphics{https://static.e-olymp.com/content/38/383d17b30e62133afac215f96c5ff496ccda07fb.jpg} Two-player game defined by its tree. Rivals make moves in turn. The first player starts the game. The game ends or tie, or win one of the players. The leaves of the tree of this game can have values equal to one of three numbers: \textbf{+1} - win the first player, \textbf{-1} - a victory the second player, \textbf{0} - a draw. Your task - to determine who will win, if both opponents follow the correct strategy. \InputFile Tree nodes are numbered by consecutive integers. The root of the tree always has the number \textbf{1}. The first line contains a positive integer \textbf{N} - the number of nodes in the tree game (\textbf{N} ≤ \textbf{1000}). Next \textbf{N}-\textbf{1} line describes the units - one row for each node (except the first). The second line contains a description of the second node of the tree, the third - the third node, etc. If the node is a leaf, the first character string - \textbf{L}, then goes blank, then the number of parent node has a space and result of the game (\textbf{+1} - win the first player to \textbf{-1} - the victory of the second, \textbf{0} - tie). If the node is internal, then the line contains \textbf{N} - the first character, followed by a space and the number of parent. \OutputFile The output file output \textbf{+1} if the first player wins, and \textbf{-1} if the second, and \textbf{0} - in the event of a draw outcome.
Time limit 1 second
Memory limit 64 MiB
Input example #1
7
N 1
N 1
L 2 -1
L 2 +1
L 3 +1
L 3 +1
Output example #1
+1