Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
tree = [None] * n
formatted_tree = [None] * n


def register_node(i, node, searching):
    for si, st in enumerate(searching[1]):
        if type(st) is int:
            if st == i:
                searching[1][si] = node
                return True
        else:
            if register_node(i, node, st):
                return True
    return False


def format(node, parent, depth):
    (i, cs) = node
    cis = [format(c, i, depth + 1) for c in cs]
    formatted_tree[i] = 'node {0}: parent = {1}, depth = {2}, {3}, [{4}]'.format(
        i, parent, depth,
        'root' if not depth else 'internal node' if cis else 'leaf',
        ', '.join(cis)
    )
    return str(i)


while n:
    l = list(map(int, input().split()))
    i, c = l[0], l[2:]
    node = (i, c)
    for p in tree:
        if not p:
            continue
        if register_node(i, node, p):
            break
    else:
        tree[i] = node

    for i, ci in enumerate(c):
        if tree[ci]:
            c[i] = tree[ci]
            tree[ci] = None

    n -= 1

format(next(filter(None, tree)), -1, 0)

for fn in formatted_tree:
    print(fn)

Fixed submission:
n = int(input())
tree = [None] * n
root = set(range(n))


def set_pd(i, parent, depth):
    node = tree[i]
    node[1], node[2] = parent, depth
    for child in node[0]:
        set_pd(child, i, depth + 1)


while n:
    l = list(map(int, input().split()))
    c = l[2:]
    tree[l[0]] = [c, None, None]
    root -= set(c)
    n -= 1

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

for i, node in enumerate(tree):
    c, p, d = node
    print('node {}: parent = {}, depth = {}, {}, [{}]'.format(
        i, p, d, 'root' if not d else 'internal node' if c else 'leaf', ', '.join(map(str, c))
    ))

Buggy python submission (verdict: Runtime Error):
n = int(input())
tree = [None] * n
formatted_tree = [None] * n


def register_node(i, node, searching):
    if not searching:
        return False
    for si, st in enumerate(searching[1]):
        if st[0] == i:
            searching[1][si] = node
            return True
        elif st[1]:
            if register_node(i, node, st):
                return True
    return False


def format(node, parent, depth):
    (i, cs) = node
    cis = [format(c, i, depth + 1) for c in cs]
    formatted_tree[i] = 'node {0}: parent = {1}, depth = {2}, {3}, [{4}]'.format(
        i, parent, depth,
        'root' if not depth else 'internal node' if cis else 'leaf',
        ', '.join(cis)
    )
    return str(i)


while n:
    l = list(map(int, input().split()))
    i, cs = l[0], l[2:]
    node = (i, [(c, None) for c in cs])
    for p in tree:
        if register_node(i, node, p):
            break
    else:
        tree[i] = node

    for i, ci in enumerate(cs):
        if tree[ci]:
            cs[i] = tree[ci]
            tree[ci] = None

    n -= 1

format(next(filter(None, tree)), -1, 0)

for fn in formatted_tree:
    print(fn)

Fixed submission:
n = int(input())
tree = [None] * n
root = set(range(n))


def set_pd(i, parent, depth):
    node = tree[i]
    node[1], node[2] = parent, depth
    for child in node[0]:
        set_pd(child, i, depth + 1)


while n:
    l = list(map(int, input().split()))
    c = l[2:]
    tree[l[0]] = [c, None, None]
    root -= set(c)
    n -= 1

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

for i, node in enumerate(tree):
    c, p, d = node
    print('node {}: parent = {}, depth = {}, {}, [{}]'.format(
        i, p, d, 'root' if not d else 'internal node' if c else 'leaf', ', '.join(map(str, c))
    ))