Maximum of a General Tree

Write a program that reads a non-empty tree of integer numbers and writes its maximum value. Your program should extend the class Tree implemented in file simple_tree.py in the public files section of the problem statement, which can be downloaded by clicking on the ’cat’ icon.

For example, given the following specification of a tree in pre-ordre, where the value stored at each node is followed by its arity

Input

1 4
  3 2
      6 0
      -6 0
  12 0
  2 4
     3 0
     5 2
       10 0
       -13 0
     11 0
     7 0
  8 0

Your program should write

Output

12

Hint

Extend the class Tree in file simple_tree.py with a new method maxim with the following header

def maxim(self):
   ...

and call that method from main after reading the tree.

Problem information

Author: Josefina Sierra Santibáñez

Generation: 2026-01-25T15:31:41.567Z

© Jutge.org, 2006–2026.
https://jutge.org