Language: C++

#include <iostream>
#include <cstdio>

constexpr int MAX_NUM = 100000;

struct Node{int p, l, r;};
int D[MAX_NUM];

Node T[MAX_NUM];

void setDepth(int tgt_id, int cur_depth) {
    D[tgt_id] = cur_depth;
    if (T[tgt_id].l != nullptr) setDepth(T[tgt_id].l, cur_depth + 1);
    if (T[tgt_id].r != nullptr) setDepth(T[tgt_id].r, cur_depth);
}

void printNode(int tgt_id) {
    int pid = -1;
    if (T[tgt_id].p != nullptr) {
        pid = T[tgt_id].p;
    }
    std::printf("node %d: parent = %d, depth = %d, ", tgt_id, pid, D[tgt_id]);
    std::string node_name = "root";
    if ((T[tgt_id].l != nullptr) || (T[tgt_id].r != nullptr)) {
        if (pid > -1) node_name = "internal node";
        printf("%s, [", node_name.c_str());
        printf("%d", T[tgt_id].l);
        int c_id = tgt_id;
        while (T[c_id].r != nullptr) {
            printf(", %d", T[c_id].r);
            c_id = T[c_id].r;
        }
        printf("]\n");
    }else {
        printf("[]\n");
    }
}

int main(int argc, char** argv) {
    int n, k;
    std::cin >> n;
    for (int i = 0; i < n; ++i) {
        int id, k, r, l;
        std::cin >> id >> k;
        for (int j = 0; j < k; j++) {
            std::cin >> r;
            if (j == 0) T[id].l = r;
            else {
                T[l].r = r;
            }
            l = r;
            T[r].p = id;
        }
    }

    int r = nullptr;
    for (int i = 0; i < n; i++) {
        if (T[i].p == nullptr) {
            r = i;
        }
    }
    setDepth(r, 0);
    for (int i = 0; i < n; i++) {
        printNode(i);
    }

}


Compiler output:
a.cc: In function 'void setDepth(int, int)':
a.cc:13:21: error: invalid operands of types 'int' and 'std::nullptr_t' to binary 'operator!='
   13 |     if (T[tgt_id].l != nullptr) setDepth(T[tgt_id].l, cur_depth + 1);
      |         ~~~~~~~~~~~~^~~~~~~~~~
a.cc:14:21: error: invalid operands of types 'int' and 'std::nullptr_t' to binary 'operator!='
   14 |     if (T[tgt_id].r != nullptr) setDepth(T[tgt_id].r, cur_depth);
      |         ~~~~~~~~~~~~^~~~~~~~~~
a.cc: In function 'void printNode(int)':
a.cc:19:21: error: invalid operands of types 'int' and 'std::nullptr_t' to binary 'operator!='
   19 |     if (T[tgt_id].p != nullptr) {
      |         ~~~~~~~~~~~~^~~~~~~~~~
a.cc:24:22: error: invalid operands of types 'int' and 'std::nullptr_t' to binary 'operator!='
   24 |     if ((T[tgt_id].l != nullptr) || (T[tgt_id].r != nullptr)) {
      |          ~~~~~~~~~~~~^~~~~~~~~~
a.cc:24:50: error: invalid operands of types 'int' and 'std::nullptr_t' to binary 'operator!='
   24 |     if ((T[tgt_id].l != nullptr) || (T[tgt_id].r != nullptr)) {
      |                                      ~~~~~~~~~~~~^~~~~~~~~~
a.cc:29:26: error: invalid operands of types 'int' and 'std::nullptr_t' to binary 'operator!='
   29 |         while (T[c_id].r != nullptr) {
      |                ~~~~~~~~~~^~~~~~~~~~
a.cc: In function 'int main(int, char**)':
a.cc:56:13: error: cannot convert 'std::nullptr_t' to 'int' in initialization
   56 |     int r = nullptr;
      |             ^~~~~~~
a.cc:58:20: error: invalid operands of types 'int' and 'std::nullptr_t' to binary 'operator=='
   58 |         if (T[i].p == nullptr) {
      |             ~~~~~~~^~~~~~~~~~