#include <cmath>
#include <iostream>
#include <string>
#include <vector>

class Node
{
public:
    Node() {
        this->_id = -1;
        this->_left = -1;
        this->_right = -1;
        this->_parent = -1;
        this->_sibling = -1;
        this->_degree = 0;
        this->_depth = 0;
        this->_height = 0;
    }

    Node(int id) {
        this->_id = id;
        this->_left = -1;
        this->_right = -1;
        this->_parent = -1;
        this->_sibling = -1;
        this->_degree = -1;
    }

    ~Node() {
        ;
    }

    const int& id() const {
        return this->_id;
    }

    int& id() {
        return this->_id;
    }

    const int& left() const {
        return this->_left;
    }

    int& left() {
        return this->_left;
    }

    const int& right() const {
        return this->_right;
    }

    int& right() {
        return this->_right;
    }

    const int& parent() const {
        return this->_parent;
    }

    int& parent() {
        return this->_parent;
    }

    const int& sibling() const {
        return this->_sibling;
    }

    int& sibling() {
        return this->_sibling;
    }

    const int& degree() const {
        return this->_degree;
    }

    int& degree() {
        return this->_degree;
    }

    const int& depth() const {
        return this->_depth;
    }

    int& depth() {
        return this->_depth;
    }

    const int& height() const {
        return this->_height;
    }

    int& height() {
        return this->_height;
    }

    std::string type() {
        if (this->_parent == -1)
            return "root";
        else if (this->_left == -1 && this->_right == -1)
            return "leaf";
        else
            return "internal node";
    }

    void print() {
        std::cout << "node "      << this->_id << ": "
                  << "parent = "  << this->_parent << ", "
                  << "sibling = " << this->_sibling << ", "
                  << "degree = "  << this->_degree << ", "
                  << "depth = "   << this->_depth << ", "
                  << "height = "  << this->_height << ", "
                  << this->type()
                  << std::endl;
    }

private:
    int _id;
    int _left;
    int _right;
    int _parent;
    int _sibling;
    int _degree;
    int _depth;
    int _height;
};

std::vector<Node> nodelist;

void setdepth(Node& node, int curdepth) {
    node.depth() = curdepth;

    if (node.left() != -1)
        setdepth(nodelist[node.left()], curdepth + 1);
    if (node.right() != -1)
        setdepth(nodelist[node.right()], curdepth + 1);
    else
        return;
}

int setheight(Node& node) {
    int height = 0;
    if (node.left() != -1)
        height = std::max(height, setheight(nodelist[node.left()]) + 1);
    if (node.right() != -1)
        height = std::max(height, setheight(nodelist[node.right()]) + 1);
    node.height() = height;

    return height;
}

int main(int argc, char const *argv[])
{
    int n;
    std::cin >> n;

    // initialize
    nodelist.resize(n);

    int id;
    int left;
    int right;
    for (int i = 0; i < n; i++) {
        std::cin >> id >> left >> right;
        nodelist[id].id() = id;
        nodelist[id].left() = left;
        nodelist[id].right() = right;

        // set parent
        nodelist[left].parent() = id;
        nodelist[right].parent() = id;

        // set sibling
        nodelist[left].sibling() = right;
        nodelist[right].sibling() = left;

        // set degree
        if (left == -1 && right == -1)
            nodelist[id].degree() = 0;
        else if (left == -1 || right == -1)
            nodelist[id].degree() = 1;
        else
            nodelist[id].degree() = 2;
    }

    // find root
    int rootid = 0;
    for (Node node : nodelist) {
        if (node.parent() == -1) {
            rootid = node.id();
            break;
        }
    }
    // set depth and height
    setdepth(nodelist[rootid], 0);
    setheight(nodelist[rootid]);

    // print
    for (Node node : nodelist)
        node.print();

    return 0;
}

Measured memory_bytes: 3156