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):
from sys import stdin

class Node(object):
    def __init__(self, parent=None, left=None, right=None,
                 name=None, sibling=None):
        self.parent = parent
        self.left = left
        self.right = right
        self.name = name
        self.sibling = sibling

def print_nodes(nodes, n):
    def get_depth(nodes, u):
        p = nodes[u].parent
        nonlocal d
        if p != None and p != -1:
            get_depth(nodes, p)
            d += 1
        return d

    def get_height(nodes, u):
        h1 = 0
        h2 = 0
        r = nodes[u].right
        l = nodes[u].left
        if r != -1:
            h1 = get_height(nodes, r) + 1
        if l != -1:
            h2 = get_height(nodes, l) + 1
        return max(h1, h2)

    for i in range(n):
        d = 0
        if nodes[i].parent == None:
            nodes[i].parent = -1
            nodes[i].sibling = -1
            nodes[i].name = "root"
        print("node {0}: parent = {1}, sibling = {2}, depth = {3}, height = {4}, {5}".format(
               i, nodes[i].parent, nodes[i].sibling, get_depth(nodes, i), get_height(nodes, i), nodes[i].name))

def read_binary_tree(nodes, n):
    for _ in range(n):
        i = [int(i) for i in stdin.readline().strip().split()]
        nodes[i[0]].left = i[1]
        nodes[i[0]].right = i[2]
        if i[1] != -1:
            nodes[i[0]].name = "internal node"
            nodes[i[1]].parent = i[0]
            nodes[i[1]].sibling = i[2]
        if i[2] != -1:
            nodes[i[0]].name = "internal node"
            nodes[i[2]].parent = i[0]
            nodes[i[2]].sibling = i[1]
        if i[1] == -1 and i[2] == -1:
            nodes[i[0]].name = "leaf"

n = int(input())
nodes = [Node() for _ in range(n)]
read_binary_tree(nodes, n)
print_nodes(nodes, n)


Fixed, accepted submission:
from sys import stdin

class Node(object):
    def __init__(self, parent=None, left=None, right=None,
                 name=None, sibling=None, degree=None):
        self.parent = parent
        self.left = left
        self.right = right
        self.name = name
        self.sibling = sibling
        self.degree = degree

def print_nodes(nodes, n):
    def get_depth(nodes, u):
        p = nodes[u].parent
        nonlocal d
        if p != None and p != -1:
            get_depth(nodes, p)
            d += 1
        return d

    def get_height(nodes, u):
        h1 = 0
        h2 = 0
        r = nodes[u].right
        l = nodes[u].left
        if r != -1:
            h1 = get_height(nodes, r) + 1
        if l != -1:
            h2 = get_height(nodes, l) + 1
        return max(h1, h2)

    for i in range(n):
        d = 0
        if nodes[i].parent == None:
            nodes[i].parent = -1
            nodes[i].sibling = -1
            nodes[i].name = "root"
        print("node {0}: parent = {1}, sibling = {2}, degree = {3}, depth = {4}, height = {5}, {6}".format(
               i, nodes[i].parent, nodes[i].sibling, nodes[i].degree, get_depth(nodes, i),
               get_height(nodes, i), nodes[i].name))

def read_binary_tree(nodes, n):
    for _ in range(n):
        i = [int(i) for i in stdin.readline().strip().split()]
        nodes[i[0]].left = i[1]
        nodes[i[0]].right = i[2]
        nodes[i[0]].degree = 0
        if i[1] != -1:
            nodes[i[0]].name = "internal node"
            nodes[i[1]].parent = i[0]
            nodes[i[1]].sibling = i[2]
            nodes[i[0]].degree += 1
        if i[2] != -1:
            nodes[i[0]].name = "internal node"
            nodes[i[2]].parent = i[0]
            nodes[i[2]].sibling = i[1]
            nodes[i[0]].degree += 1
        if i[1] == -1 and i[2] == -1:
            nodes[i[0]].name = "leaf"

n = int(input())
nodes = [Node() for _ in range(n)]
read_binary_tree(nodes, n)
print_nodes(nodes, n)