Language: C++



class Node:
    def __init__(self, num, children):
        self.num = num
        self.children = children
        self.parents = -1
        self.type = None
        self.depth = 0

    def output(self):
        print('node {0}: parent = {1}, depth = {2}, {3}, {4}'.format(self.num,
                                                                      self.parents,
                                                                      self.depth,
                                                                      self.type,
                                                                      self.children))


def set_node(num, children):
    node = Node(num, children)
    T[num] = node
    for n in children:
        T[-1] -= n  # ?????£???T[-1]???root???????????????????????????


def set_pdt(n_i, parent, depth):
    node = T[n_i]
    node.parents = parent
    node.depth = depth
    if node.children:
        node.type = 'internal node'
        for n in node.children:
            set_pdt(n, n_i, depth + 1)
    else:
        node.type = 'leaf'


n = int(input())
tree = [list(map(int, input().split())) for i in range(n)]
T = [None] * n
T += [n * (n - 1) // 2]
for j in tree:
    set_node(j[0], j[2:])

set_pdt(T[-1], -1, 0)

T[T[-1]].type = 'root'

for n in T[:-1]:
    n.output()

Compiler output:
a.cc:12:15: warning: multi-character literal with 45 characters exceeds 'int' size of 4 bytes
   12 |         print('node {0}: parent = {1}, depth = {2}, {3}, {4}'.format(self.num,
      |               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:23:21: error: stray '#' in program
   23 |         T[-1] -= n  # ?????£???T[-1]???root???????????????????????????
      |                     ^
a.cc:23:28: error: extended character £ is not valid in an identifier
   23 |         T[-1] -= n  # ?????£???T[-1]???root???????????????????????????
      |                            ^
a.cc:31:21: warning: multi-character literal with 13 characters exceeds 'int' size of 4 bytes
   31 |         node.type = 'internal node'
      |                     ^~~~~~~~~~~~~~~
a.cc:35:21: warning: multi-character character constant [-Wmultichar]
   35 |         node.type = 'leaf'
      |                     ^~~~~~
a.cc:47:17: warning: multi-character character constant [-Wmultichar]
   47 | T[T[-1]].type = 'root'
      |                 ^~~~~~
a.cc:4:9: error: expected class-name before '__init__'
    4 |     def __init__(self, num, children):
      |         ^~~~~~~~
a.cc:4:9: error: expected '{' before '__init__'
a.cc:4:18: error: 'self' was not declared in this scope
    4 |     def __init__(self, num, children):
      |                  ^~~~
a.cc:4:24: error: 'num' was not declared in this scope; did you mean 'enum'?
    4 |     def __init__(self, num, children):
      |                        ^~~
      |                        enum
a.cc:4:29: error: 'children' was not declared in this scope
    4 |     def __init__(self, num, children):
      |                             ^~~~~~~~
a.cc:4:37: error: expression list treated as compound expression in initializer [-fpermissive]
    4 |     def __init__(self, num, children):
      |                                     ^