Language: C++

# coding: utf-8
# Here your code !
from collections import deque 

class Node:
    def __init__(self):
        self.id = -1
        self.k = -1
        self.depth = -1
        self.parent = -1
        self.type = 'root'
        self.end = False
        self.children = []
        
def find_root_id(nodes):
    i = 0
    rootid = -1
    while nodes[i].parent != -1:
        nodes[i]
        i += 1
    else:
        rootid = nodes[i].id
        return rootid
        
def set_depth(rootid, nodes):
    que = deque()
    depth = 0
    node = nodes[rootid]
    que = deque(node.children)
    for i in que:
        nodes[i].depth = depth + 1
    depth += 1
    
    while que:
        for i in range(len(que)):
            for child in nodes[que.popleft()].children:
                que.append(child)
        for j in que:
            nodes[j].depth = depth + 1
        depth += 1

n = int(raw_input())
nodes = []
for i in range(n):
    node = Node()
    ls =  map(int, raw_input().split())
    node.id = ls[0]
    node.k = ls[1]
    if node.k == 0:
        pass
    else:
        node.children = ls[2:]
    nodes.append(node)
    
nodes = sorted(nodes, key=lambda node:node.id)
for node in nodes:
    for child in node.children:
        nodes[child].parent = node.id
        
for node in nodes:
    if node.children == []:
        if node.parent != -1:
            node.type = 'leaf'
    else:
        if node.parent != -1:
            node.type = 'internal node'

rootid = find_root_id(nodes)
nodes[rootid].depth = 0

def set_depth(rootid, nodes):
    que = deque()
    depth = 0
    node = nodes[rootid]
    que = deque(node.children)
    for i in que:
        nodes[i].depth = depth + 1
    depth += 1
    
    while que:
        for i in range(len(que)):
            for child in nodes[que.popleft()].children:
                que.append(child)
        for j in que:
            nodes[j].depth = depth + 1
        depth += 1

set_depth(rootid, nodes)
for node in nodes:#sorted(nodes, key=lambda node:node.id):
    print 'node %s: parent = %s, depth = %s, %s, %s'%(node.id,
    node.parent, node.depth, node.type, node.children)

Compiler output:
a.cc:1:3: error: invalid preprocessing directive #coding
    1 | # coding: utf-8
      |   ^~~~~~
a.cc:2:3: error: invalid preprocessing directive #Here
    2 | # Here your code !
      |   ^~~~
a.cc:11:21: warning: multi-character character constant [-Wmultichar]
   11 |         self.type = 'root'
      |                     ^~~~~~
a.cc:63:25: warning: multi-character character constant [-Wmultichar]
   63 |             node.type = 'leaf'
      |                         ^~~~~~
a.cc:66:25: warning: multi-character literal with 13 characters exceeds 'int' size of 4 bytes
   66 |             node.type = 'internal node'
      |                         ^~~~~~~~~~~~~~~
a.cc:89:19: error: stray '#' in program
   89 | for node in nodes:#sorted(nodes, key=lambda node:node.id):
      |                   ^
a.cc:90:11: warning: multi-character literal with 40 characters exceeds 'int' size of 4 bytes
   90 |     print 'node %s: parent = %s, depth = %s, %s, %s'%(node.id,
      |           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:3:1: error: 'from' does not name a type
    3 | from collections import deque
      | ^~~~