1319. Three-coloring of binary trees

单点时限: 2.0 sec

内存限制: 256 MB

A tree consists of a node and some (zero, one or two) subtrees connected to it. These subtrees are called children.

A specification of the tree is a sequence of digits. If the number of children in the tree is:

1.zero, then the specification is a sequence with only one element ‘0’;

2.one, the specification begins with ‘1’ followed by the specification of the child;

3.two, the specification begins with ‘2’ followed by the specification of the first child, and then by the specification of the second child.

Each of the vertices in the tree must be painted either red or green or blue.

However, we need to obey the following rules:

1.the vertex and its child cannot have the same color,

2.if a vertex has two children, then they must have different colors.

How many vertices may be painted green?

Task

Write a program which:

1.reads the specification of the tree,

2.computes the maximal and the minimal number of vertices that may be painted green,

writes the results.

输入格式

The first and only line of the input file TRO.IN consists of one word (no longer then 10000 characters), which is a specification of a tree.

输出格式

Your program should write in the first and only line of the output file TRO.OUT exactly two integers separated by a single space, which respectively denote the maximal and the minimal number of vertices that may be painted green.

样例

Input
1122002010
Output
5 2

2 人解决,3 人已尝试。

2 份提交通过,共有 15 份提交。

9.0 EMB 奖励。

创建: 16 年,9 月前.

修改: 6 年,8 月前.

最后提交: 3 年,5 月前.

来源: POI 1999 III Stage

题目标签