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):
#coding:utf-8

n = int(input())
T = [list(map(int, input().split())) for i in range(n)]
A = []

class binaryTree:
    def __init__(self, x, y, z):
        self.data = x
        self.par = y
        self.depth = z
        
    def makeTree(self,tree):
        parID = tree.data[0]
        t = T[parID]
        depth = tree.depth
        
        if tree.par == -1:
            tree.kind = "root"
        elif t[1] == -1 and t[2] == -1:
            tree.kind = "leaf"
        else:
            tree.kind = "international node"

        if t[1] == -1 and t[2] == -1:
            tree.deg = 0
            tree.l = None
            tree.r = None

        if t[1] != -1:
            tree.l = binaryTree(T[t[1]], parID, depth+1)
            l_tree = tree.l
            if t[2] != -1:
                tree.deg = 2
                l_tree.sib = t[2]
            else:
                tree.deg = 1
                l_tree.sib = -1
            self.makeTree(self, l_tree)
        
        else:
            tree.l = None

        if t[2] != -1:
            tree.r = binaryTree(T[t[2]], parID, depth+1)
            r_tree = tree.r
            if t[1] != -1:
                tree.deg = 2
                r_tree.sib = t[1]
            else:
                tree.deg = 1
                r_tree.sib = -1
            self.makeTree(self, r_tree)
        else:
            tree.r = None


def setHeight(tree):
    h1 = h2 = 0
    if tree.l != None:
        h1 = setHeight(tree.l) + 1
    if tree.r != None:
        h2 = setHeight(tree.r) + 1
    if tree.r == None and tree.l == None:
        tree.hei = 0
        return 0
    tree.hei = max(h1,h2)
    return max(h1, h2)


par = -1
depth = 0
tree = binaryTree(T[0], par,depth)
tree.sib = -1

binaryTree.makeTree(binaryTree, tree)
setHeight(tree)
  

ID = tree.data[0]
parent = tree.par
sibling = tree.sib
degree = tree.deg
depth = tree.depth
height = tree.hei
kind = tree.kind


def printer(tree):
        ID = tree.data[0]
        parent = tree.par
        sibling = tree.sib
        degree = tree.deg
        depth = tree.depth
        height = tree.hei
        kind = tree.kind
        print("node {}: parent = {}, sibling = {}, degree = {}, depth = {}, height = {}, {}"\
              .format(ID, parent, sibling, degree, depth, height, kind))

        if tree.l != None:
            l_tree = tree.l
            printer(l_tree)

        if tree.r != None:
            r_tree = tree.r
            printer(r_tree)
        
printer(tree)


Fixed, accepted submission:
#coding:utf-8

n = int(input())
T = [list(map(int, input().split())) for i in range(n)]
A = [False for i in range(n)]

class binaryTree:
    def __init__(self, node, x=-1):
        self.node = node
        self.p = x
    
    def partialTree(self,tree,left, right):
        node = tree.node
        if left != -1:
            if A[left]:
                A[left].p = tree
                tree.l = A[left]
            else:
                tree.l = binaryTree(left, node)
                A[left] = tree.l
                tree.l.p = tree
        else:
            tree.l = binaryTree(left, node)
            tree.l.node = -1
            
        if right != -1:
            if A[right]:
                A[right].p = tree
                tree.r = A[right]
            else:
                tree.r = binaryTree(right, node)
                A[right] = tree.r
                tree.r.p = tree
        else:
            tree.r = binaryTree(right, node)
            tree.r.node = -1
            
def searchParent():
    p_tree = A[0]
    while p_tree.p != -1:
        p_tree = p_tree.p
    return p_tree

     
def setHeight(tree):
    h1 = h2 = 0
    if tree.l.node != -1:
        h1 = setHeight(tree.l) + 1
    if tree.r.node != -1:
        h2 = setHeight(tree.r) + 1
    if tree.l.node == -1 and tree.r.node == -1:
        tree.hei = 0
        return 0
    tree.hei = max(h1,h2)
    return max(h1, h2)

def setDepth(tree,depth):
    tree.dep = depth
    depth += 1
    if tree.l.node != -1:
        setDepth(tree.l,depth)

    if tree.r.node != -1:
        setDepth(tree.r,depth)

def getSibling(tree):
    if tree.p == -1:
        return -1
    if tree.p.l.node != -1 and tree.p.l.node != tree.node:
        return tree.p.l.node
    if tree.p.r.node != -1 and tree.p.r.node != tree.node:
        return tree.p.r.node
    return -1

        
def makeTree():
    for i in range(n):
        t = T[i]
        node = t[0]
        left = t[1]
        right = t[2]
        if A[node]:
            tree = A[node]
        else:
            tree = binaryTree(node)
            A[node] = tree
        binaryTree.partialTree(binaryTree, tree,left,right)

makeTree()
p_tree = searchParent()
setHeight(p_tree)
depth = 0
setDepth(p_tree,depth)


for i in range(n):
    tree = A[i]
    tree.sib = getSibling(tree)
    deg = 0
    if tree.r.node != -1:
        deg += 1

    if tree.l.node != -1:
        deg += 1

    if tree.p == -1:
        kind = "root"
    else:
        if deg == 0:
            kind = "leaf"
        else:
            kind = "internal node"

    ID = i
    if tree.p == -1:
        parent = -1
    else:
        parent = tree.p.node
    sibling = tree.sib
    degree = deg
    depth = tree.dep
    height = tree.hei

    print("node {}: parent = {}, sibling = {}, degree = {}, depth = {}, height = {}, {}"\
          .format(ID, parent, sibling, degree, depth, height, kind))