Buggy python submission (verdict: Time Limit Exceeded):
class Tree:
    def __init__(self):
        self.nodes = {}
        self.roots = []

    def add(self, node):
        for i_number in self.roots:
            if i_number in node.degree:
                node.t = "root"
                r = self.nodes[i_number]
                if 0 < len(r.degree):
                    r.t = 'internal node'
                else:
                    r.t = 'leaf'
                r.parent = node.i
                self.roots.remove(i_number)
                self.roots.append(node.i)

        if len(self.nodes) == 0:
            node.t = 'root'
            self.roots.append(node.i)
        elif node.t != 'leaf' and node.t != 'root':
            node.t = 'internal node'

        if node.t != "root":
            for k, n in self.nodes.items():
                if node.i in n.degree:
                    node.parent = n.i

        self.nodes[node.i] = node

    def set_parent(self):
        for n in self.nodes.values():
            for deg in n.degree:
                child = self.nodes[deg]
                child.parent = n.i

    def calc_depth(self):
        for n in self.nodes.values():
            if n.parent == -1:
                continue
            else:
                p = self.nodes[n.i]
                depth = 0
                while not (p.parent == -1):
                    p = self.nodes[p.parent]
                    depth += 1
                n.depth = depth


class Node:
    def __init__(self, i=-1, parent=-1, depth=0, t="n", degree=[]):
        self.i = i
        self.parent = parent
        self.depth = depth
        self.t = t
        self.degree = degree
        if 0 < len(self.degree):
            self.leaf = False
        else:
            self.leaf = True
            self.t = "leaf"

    def show(self):
        ans = 'node {}: parent = {}, depth = {}, {}, {}'.format(self.i, self.parent, self.depth, self.t, self.degree)
        print(ans)

n = int(input())
tree = Tree()
for i in range(n):
    A = list(map(int, input().split()))
    node = Node(i=A[0], degree=A[2:])
    tree.add(node)

tree.set_parent()
tree.calc_depth()

for k, node in tree.nodes.items():
    node.show()

Fixed submission:
def set_info(i, p, d):
    r = T[i]
    r[1], r[2] = p, d
    for c in r[0]:
        set_info(c, i, d+1)

n = int(input())
T = [None] * n
root = set(range(n))

for i in range(n):
    A = list(map(int, input().split()))
    ch = A[2:]
    T[A[0]] = [ch, None, None]
    root -= set(ch)

set_info(root.pop(), -1, 0)

for i,node in enumerate(T):
    ch, p, d = node
    print('node {}: parent = {}, depth = {}, {}, {}'.format(
            i, p, d, 'root' if not d else 'internal node' if ch else 'leaf', ch
        ))

Buggy python submission (verdict: Time Limit Exceeded):
class Node:
    def __init__(self):
        self.p = None
        self.depth = None
        self.l = None
        self.r = None

    def show(self, i):
        global T
        ans = 'node {}: parent = {}, depth = {}, {}, {}'.format(i, self.p, self.depth, self.t(), self.degree(T))
        print(ans)

    def degree(self, T):
        if self.l != None:
            deg = [self.l]
            ch = T[self.l]
            while ch.r != None:
                deg.append(ch.r)
                ch = T[ch.r]
            return deg
        else:
            return []

    def t(self):
        if self.p == -1:
            return 'root'
        elif self.l == None:
            return 'leaf'
        else:
            return 'internal node'

def set_depth(root, d):
    r = T[root]
    r.depth = d
    if r.r != None:
        set_depth(r.r, d)
    if r.l != None:
        set_depth(r.l, d+1)

n = int(input())

T = [Node() for x in range(n)]
for i in range(n):
    A = list(map(int, input().split()))
    l = 0
    for x in range(A[1]):
        if x == 0:
            T[A[0]].l = A[2:][x]
        else:
            T[l].r = A[2:][x]
        l = A[2:][x]
        T[A[2:][x]].p = A[0]

root = None
for i in range(n):
    if T[i].p == None:
        root = i
        T[root].p = -1

set_depth(root, 0)

count = 0
for node in T:
    node.show(count)
    count += 1

Fixed submission:
def set_info(i, p, d):
    r = T[i]
    r[1], r[2] = p, d
    for c in r[0]:
        set_info(c, i, d+1)

n = int(input())
T = [None] * n
root = set(range(n))

for i in range(n):
    A = list(map(int, input().split()))
    ch = A[2:]
    T[A[0]] = [ch, None, None]
    root -= set(ch)

set_info(root.pop(), -1, 0)

for i,node in enumerate(T):
    ch, p, d = node
    print('node {}: parent = {}, depth = {}, {}, {}'.format(
            i, p, d, 'root' if not d else 'internal node' if ch else 'leaf', ch
        ))