eolymp
bolt
Спробуйте наш новий інтерфейс для відправки розв'язків
Задачі

Optimal alpha beta pruning

Optimal alpha beta pruning

Fox Ciel is developing an artificial intelligence (AI) for a game. This game is described as a game tree \textbf{T} with \textbf{n}vertices. Each node in the game has an evaluation value which shows how good a situation is. This value is the same as maximum value of child nodes’ values multiplied by \textbf{-1}. Values on leaf nodes are evaluated with Ciel’s special function - which is a bit heavy. So, she will use alpha-beta pruning for getting root node’s evaluation value to decrease the number of leaf nodes to be calculated. By the way, changing evaluation order of child nodes affects the number of calculation on the leaf nodes. Therefore, Ciel wants to know the minimum and maximum number of times to calculate in leaf nodes when she could evaluate child node in arbitrary order. She asked you to calculate minimum evaluation number of times and maximum evaluation number of times in leaf nodes. Ciel uses following algotithm: \textbf{function negamax(node, α, β)} \textbf{if node is a terminal node} \textbf{return value of leaf node} \textbf{else} \textbf{foreach child of node} \textbf{val := -negamax(child, -β, -α)} \textbf{if val >= β} \textbf{return val} \textbf{if val > α} \textbf{α := val} \textbf{return α} \InputFile Input follows following format: \textbf{n} \textbf{p_1 p_2 ... p_n} \textbf{k_1 t_11 t_12 ... t_1k} \textbf{...} \textbf{k_n t_n1 t_n2 ... t_nk} The first line contains an integer \textbf{n}, which means the number of vertices in game tree \textbf{T}. The second line contains \textbf{n} integers \textbf{p_i}, which means the evaluation value of vertex \textbf{i}. Then, next \textbf{n} lines which contain the information of game tree \textbf{T}. \textbf{k_i} is the number of child nodes of vertex \textbf{i}, and \textbf{t_ij} is the indices of the child node of vertex \textbf{i}. Input follows following constraints: \begin{itemize} \item \textbf{2} ≤ \textbf{n} ≤ \textbf{100} \item \textbf{−10000} ≤ \textbf{p_i} ≤ \textbf{10000} \item \textbf{0} ≤ \textbf{k_i} ≤ \textbf{5} \item \textbf{2} ≤ \textbf{t_ij} ≤ \textbf{n} \item Index of root node is \textbf{1}. \item Evaluation value except leaf node is always \textbf{0}. This does not mean the evaluation values of non-leaf nodes are \textbf{0}. You have to calculate them if necessary. \item Leaf node sometimes have evaluation value of \textbf{0}. \item Game tree \textbf{T} is tree structure. \end{itemize} \OutputFile Print the minimum evaluation number of times and the maximum evaluation number of times in leaf node. Please separated by whitespace between minimum and maximum.
Ліміт часу 2 секунди
Ліміт використання пам'яті 256 MiB
Вхідні дані #1
3
0 1 1
2 2 3
0
0
Вихідні дані #1
2 2
Джерело Japan Alumni Group Summer Camp 2013 Day 4, 2013/09/23