#P2585. [ZJOI2006] 三色二叉树

    ID: 1598 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>动态规划,dp搜索2006各省省选浙江深度优先搜索,DFS

[ZJOI2006] 三色二叉树

Description

A binary tree can be represented as a character sequence consisting of 00, 11, and 22 according to the following rules, which we call the "binary tree sequence SS":

$$S= \begin{cases} 0 & \text{indicates that this node has no child} \\ 1S_1 & \text{indicates that this node has one child, and } S_1 \text{ is the binary tree sequence of its subtree} \\ 2S_1S_2 & \text{indicates that this node has two children, where } S_1 \text{ and } S_2 \text{ are the binary tree sequences of its two subtrees} \end{cases}$$

For example, the binary tree shown in the figure below can be represented by the binary tree sequence S=21200110S=\texttt{21200110}.

haha.png

Your task is to color the nodes of a binary tree. Each node can be colored red, green, or blue. A node must have a different color from each of its children, and if it has two children, then the two children must also have different colors. Given the binary tree sequence of a tree, determine the maximum and minimum number of nodes that can be colored green.

Input Format

The input contains a single line with a string ss, which represents the binary tree sequence.

Output Format

Output a single line with two numbers, indicating the maximum and then the minimum number of nodes that can be colored green.

1122002010
5 2

Hint

Constraints

For all test points, it is guaranteed that 1s5×1051 \le |s| \le 5 \times 10^5, and ss contains only the characters 0 1 2.

Translated by ChatGPT 5