|
|||||||
|
Three-coloring of binary trees
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:
Each of the vertices in the tree must be painted either red or green or blue.
How many vertices may be painted green? TaskWrite a program which:
InputThe 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. OutputYour 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. ExampleFor the input file TRO.IN: 1122002010 the correct answer is the output file TRO.OUT: 5 2 |