Problem:
A rooted binary tree is a tree with a root node in which every node has at most two children.  Your task is to write a program which reads a rooted binary tree _T_ and prints the following information for each node _u_ of _T_ :    * node ID of _u_   * parent of _u_   * sibling of _u_   * the number of children of _u_   * depth of _u_   * height of _u_   * node type (root, internal node or leaf)  If two nodes have the same parent, they are **siblings**. Here, if _u_ and _v_ have the same parent, we say _u_ is a sibling of _v_ (vice versa).  The height of a node in a tree is the number of edges on the longest simple downward path from the node to a leaf.  Here, the given binary tree consists of _n_ nodes and evey node has a unique ID from 0 to _n_ -1.

Incorrect submission (verdict: Wrong Answer):
N = int(input())

binary_tree = [{"parent": -1, "sibling": -1} for _ in range(N)]
for _ in range(N):
    node_input = input()
    id, left, right = map(int, node_input.split())

    binary_tree[id]["left"] = left
    binary_tree[id]["right"] = right

    degree = 0
    if left != -1:
        degree += 1
        binary_tree[left]["parent"] = id
        binary_tree[left]["sibling"] = right
    if right != -1:
        degree += 1
        binary_tree[right]["parent"] = id
        binary_tree[right]["sibling"] = left
    binary_tree[id]["degree"] = degree


def measure_depth_and_height(id, depth):
    H[id] = max(H[id], depth)

    parent_id = binary_tree[id]["parent"]
    if parent_id == -1:
        return depth

    return measure_depth_and_height(parent_id, depth+1)

D = [0 for i in range(N)]
H = [0 for i in range(N)]
for id in range(N):
    depth = measure_depth_and_height(id, 0)
    D[id] = depth


def get_type(node):
    if node["degree"] == 0:
        return "leaf"
    if node["parent"] == -1:
        return "parent"
    return "internal node"

for id in range(N):
    node = binary_tree[id]
    parent_id = node["parent"]
    sibling_id = node["sibling"]
    degree = node["degree"]
    node_type = get_type(node)
    print("node {}: parent = {}, sibling = {}, degree = {}, depth = {}, height= {}, {}".format(id, parent_id, sibling_id, degree, D[id], H[id], node_type))


Fixed, accepted submission:
N = int(input())

class Node():
    def __init__(self, parent = -1, left = -1, right = -1):
        self.parent = parent
        self.left = left
        self.right = right

binary_tree = [Node() for _ in range(N)]
for _ in range(N):
    node_input = input()
    id, left, right = map(int, node_input.split())

    binary_tree[id].left = left
    binary_tree[id].right = right

    if left != -1:
        binary_tree[left].parent = id
    if right != -1:
        binary_tree[right].parent = id


def set_depth(id, depth):
    if id == -1:
        return

    D[id] = depth
    set_depth(binary_tree[id].left, depth+1)
    set_depth(binary_tree[id].right, depth+1)

def set_height(id):
    h1, h2 = 0, 0
    if binary_tree[id].left != -1:
        h1 = set_height(binary_tree[id].left) + 1
    if binary_tree[id].right != -1:
        h2 = set_height(binary_tree[id].right) + 1
    H[id] = max(h1, h2)
    return H[id]


D = [0 for i in range(N)]
H = [0 for i in range(N)]
for id in range(N):
    if binary_tree[id].parent == -1:
        set_depth(id, 0)
        set_height(id)
        break



def get_sibling(id):
    parent_id = node.parent
    if parent_id == -1:
        return -1
    if binary_tree[parent_id].left != id:
        return binary_tree[parent_id].left
    else:
        return binary_tree[parent_id].right

def get_degree(node):
    degree = 0
    if node.left != -1:
        degree += 1
    if node.right != -1:
        degree += 1
    return degree

def get_type(node, dgree):
    if node.parent == -1:
        return "root"
    if degree == 0:
        return "leaf"
    return "internal node"

for id in range(N):
    node = binary_tree[id]
    parent_id = node.parent
    sibling_id = get_sibling(id)
    degree = get_degree(node)
    node_type = get_type(node, degree)
    print("node {}: parent = {}, sibling = {}, degree = {}, depth = {}, height = {}, {}".format(id, parent_id, sibling_id, degree, D[id], H[id], node_type))