alexjercan/bugnet huggingface dataset:
Problem p02279 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef vector<int> V;
void func(int node, int par, int rang);
bool flg[100000] = {0};
int n, u, k, c;
V v[100000];
struct Node {
  int parent, depth;
};
Node T[100000];
int main(void) {

  int i, j;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> u >> k;
    T[i].parent = 0;
    T[i].depth = 0;
    for (j = 0; j < k; j++) {
      cin >> c;
      flg[c] = 1;
      v[u].push_back(c);
    }
  }
  for (i = 0; i < n; i++) {
    if (!flg[i]) {
      func(i, -1, 0);
    }
  }
  // cout<<"check2"<<endl;
  for (i = 0; i < n; i++) {
    cout << "node " << i << ": parent = " << T[i].parent
         << ", depth = " << T[i].depth << ", ";
    if (v[i].empty()) {
      if (T[i].parent == -1) {
        cout << "root, []" << endl;
      } else {
        cout << "leaf, []" << endl;
      }
    } else {
      if (T[i].parent == -1) {
        cout << "root, [" << v[i][0];
        for (j = 1; j < v[i].size(); j++) {
          cout << ", " << v[i][j];
        }
        cout << "]" << endl;
      } else {
        cout << "internal node, [" << v[i][0];
        for (j = 1; j < v[i].size(); j++) {
          cout << ", " << v[i][j];
        }
        cout << "]" << endl;
      }
    }
  }
  return 0;
}
void func(int node, int par, int rang) {
  int i;
  // cout<<"check"<<endl;
  T[node].parent = par;
  T[node].depth = rang;
  // cout<<"cheack1"<<endl;
  for (i = 0; i < v[node].size(); i++) {
    func(v[node][i], node, rang + 1);
  }
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef vector<int> V;
void func(int node, int par, int rang);
bool flg[100000] = {0};
int n, u, k, c;
V v[100000];
struct Node {
  int parent, depth;
};
Node T[100000];
int main(void) {

  int i, j;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> u >> k;
    T[i].parent = 0;
    T[i].depth = 0;
    for (j = 0; j < k; j++) {
      cin >> c;
      flg[c] = 1;
      v[u].push_back(c);
    }
  }
  for (i = 0; i < n; i++) {
    if (!flg[i]) {
      func(i, -1, 0);
    }
  }
  for (i = 0; i < n; i++) {
    cout << "node " << i << ": parent = " << T[i].parent
         << ", depth = " << T[i].depth << ", ";
    if (T[i].parent == -1) {
      cout << "root, [" << v[i][0];
      for (j = 1; j < v[i].size(); j++) {
        cout << ", " << v[i][j];
      }
      cout << "]" << endl;
    } else {
      if (v[i].empty()) {
        cout << "leaf, []" << endl;
      } else {
        cout << "internal node, [" << v[i][0];
        for (j = 1; j < v[i].size(); j++) {
          cout << ", " << v[i][j];
        }
        cout << "]" << endl;
      }
    }
  }
  return 0;
}
void func(int node, int par, int rang) {
  int i;
  T[node].parent = par;
  T[node].depth = rang;
  for (i = 0; i < v[node].size(); i++) {
    func(v[node][i], node, rang + 1);
  }
}
Problem p02279 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <fstream>
#include <stdio.h>
using namespace std;
struct jiedian {
  int fu, left, right, shengdu;
} a[2000005];
const int null = -1;
void res(int u, int p) {
  a[u].shengdu = p;
  if (a[u].right != null)
    res(a[u].right, p);
  if (a[u].left != null)
    res(a[u].left, p + 1);
}

int main() {

  int n;
  int p;
  int k;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    a[i].fu = a[i].left = a[i].right = null;
  }

  for (int i = 0; i < n; i++) {
    int node, du;
    scanf("%d%d", &node, &du);
    for (int j = 0; j < du; j++) {
      scanf("%d", &k);
      if (j == 0)
        a[node].left = k;
      else
        a[p].right = k;
      p = k;
      a[k].fu = node;
    }
  }
  /*for(int i=0;i<n;i++)
  {
      printf("%d %d %d\\n",a[i].fu,a[i].left,a[i].right);
  }*/
  int hd;
  for (int i = 0; i < n; i++) {
    if (a[i].fu == null)
      hd = i;
  }
  res(hd, 0);
  for (int i = 0; i < n; i++) {
    // printf("node %d: parent = %d, depth = %d, ",i,a[i].fu,a[i].shengdu);
    printf("node %d: ", i);
    printf("parent = %d, ", a[i].fu);
    printf("depth = %d, ", a[i].shengdu);
    if (a[i].fu == null)
      printf("root, ");
    else if (a[i].left == null)
      printf("leaf, ");
    else
      printf("internal node, ");
    printf("[");
    // printf("%d ",a[i].left);
    for (int j = 0, c = a[i].left; c != null; j++, c = a[c].right) {
      if (j)
        printf(", ");
      printf("%d", c);
    }
    printf("]\\n");
  }
  return 0;
}

Error: -11

Fixed submission:

#include <iostream>
using namespace std;
#define MAX 100005
#define NIL -1
struct Node {
  int p, l, r;
};
Node T[MAX];
int n, D[MAX];
void print(int u) {
  int i, c;
  cout << "node " << u << ";";
  cout << "parent=" << T[u].p << ",";
  cout << "depth=" << D[u] << ", ";
  if (T[u].p == NIL)
    cout << "root, ";
  else if (T[u].l == NIL)
    cout << "leaf, ";
  else
    cout << "internal node, ";

  cout << "[";

  for (i = 0, c = T[u].l; c != NIL; c = T[c].r, i++) {
    if (i)
      cout << ",";
    cout << c;
  }
  cout << "]" << endl;
}
int depth(int u, int p) {
  D[u] = p;
  if (T[u].r != NIL)
    depth(T[u].r, p);
  if (T[u].l != NIL)
    depth(T[u].l, p + 1);
}
int main() {
  int i, j, d, v, c, l, r;
  for (i = 0; i < n; i++)
    T[i].p = T[i].l = T[i].r = NIL;
  for (i = 0; i < n; i++) {
    cin >> v >> d;
    for (j = 0; j < d; j++) {
      cin >> c;
      if (j == 0)
        T[c].l = c;
      else
        T[l].r = c;
      l = c;
      T[c].p = v;
    }
  }
  for (i = 0; i < n; i++) {
    if (T[i].p == NIL)
      r = i;
  }
  depth(r, 0);
  for (int i = 0; i < n; i++)
    print(i);
  return 0;
}
Problem p02279 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
#define MAX 100005
#define NIL -1

struct node {
  int p, l, r;
};

node T[MAX];
int n, D[MAX];

void print(int u) {
  int i, c;
  cout << "node " << u << ": ";
  cout << "parent = " << T[u].p << ", ";
  cout << "depth = " << D[u] << ", ";

  if (T[u].p == NIL)
    cout << "root, ";
  else if (T[u].l == NIL)
    cout << "leaf, ";
  else
    cout << "internal node, ";
  cout << "[";

  for (i = 0, c = T[u].l; c != NIL; i++, c = T[c].r) {
    if (i)
      cout << ", ";
    cout << c;
  }
  cout << "]" << endl;
}

int rec(int u, int p) {
  D[u] = p;
  if (T[u].r != NIL)
    rec(T[u].r, p);
  if (T[u].l != NIL)
    rec(T[u].l, p + 1);
}

int main() {
  int i, j, d, c, v, l, r;
  cin >> n;
  for (i = 0; i < n; i++)
    T[i].p = T[i].l = T[i].r = NIL;

  for (i = 0; i < n; i++) {
    cin >> v >> d; // v=±???£?d=¶?
    for (j = 0; j < d; j++) {
      cin >> c;
      if (j == 0)
        T[v].l = c;
      else
        T[l].r = c;
      l = c;
      T[c].p = v;
    }
  }
  for (i = 0; i < n; i++) {
    if (T[i].p == NIL)
      r = i;
  }
  rec(r, 0);
  for (i = 0; i < n; i++)
    print(i);
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

struct node {
  int p, l, r;
};

node T[100005];
int n, D[100005];

void print(int u) {
  int i, c;
  cout << "node" << u << ":";
  cout << "parent " << T[u].p << ",";
  cout << "depth=" << D[u] << ",";
  if (T[u].p == -1)
    cout << "root,";
  else if (T[u].l == -1)
    cout << "left,";
  else
    cout << "internal node,";
  cout << "[";

  for (i = 0, c = T[u].l; c != -1; i++, c = T[c].r) {
    if (i)
      cout << ",";
    cout << c;
  }
  cout << "]" << endl;
}

int rec(int u, int p) {
  D[u] = p;
  if (T[u].r != -1)
    rec(T[u].r, p);
  if (T[u].l != -1)
    rec(T[u].l, p + 1);
}

int main() {
  int i, j, t, d, c, v, l, r;
  cin >> n;
  for (i = 0; i < n; i++)
    T[i].p = T[i].r = -1;
  for (i = 0; i < n; i++) {
    cin >> v >> d; // v=?号；d=度
    for (j = 0; j < d; j++) {
      cin >> c;
      if (j == 0)
        T[v].l = c;
      else
        T[l].r = c;
      l = c;
      T[c].p = v;
    }
  }
  for (i = 0; i < n; i++) {
    if (T[i].p == -1)
      r = i;
  }
  rec(r, 0);
  for (i = 0; i < n; i++)
    print(i);

  return 0;
}
Problem p02279 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>

using namespace std;

int nil = -1;
int N;

struct Node {
  int id;
  int left, right, parent;
};

Node *nodes;

/*
 * 左子右兄弟表現
 */

int depth(int m) {
  int d = 0;
  while (true) {
    if (nodes[m].parent != nil) {
      d++;
      m = nodes[m].parent;
    } else
      break;
  }
  return d;
}

string type(int m) {
  if (nodes[m].parent == nil) {
    return "root";
  } else if (nodes[m].left != nil) {
    return "internal node";
  } else {
    return "leaf";
  }
}

int main() {
  cin >> N;
  nodes = new Node[N];

  for (int k = 0; k < N; ++k) {
    nodes[k].left = nodes[k].right = nodes[k].parent = nil;
  }

  for (int i = 0; i < N; ++i) {
    int d;
    int nod;
    cin >> nod >> d;
    nodes[i].id = nod;
    int l;
    for (int j = 0; j < d; ++j) {
      int c;
      cin >> c;
      if (j == 0)
        nodes[nod].left = c;
      else
        nodes[l].right = c;

      l = c;
      nodes[c].parent = nod;
    }
  }

  for (int m = 0; m < N; ++m) {
    cout << "node " << m << ": parent = " << nodes[m].parent
         << ", depth = " << depth(m) << ", " << type(m);
    int i = nodes[m].left;
    if (nodes[m].left == nil) {
      cout << ", []" << endl;
      continue;
    }
    cout << ", [";
    while (true) {
      cout << i;
      if (nodes[i].right != nil) {
        cout << ", ";
        i = nodes[i].right;
      } else
        break;
    }
    cout << "]" << endl;
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

int nil = -1;
int N;

struct Node {
  int id;
  int left, right, parent;
};

Node *nodes;

/*
 * 左子右兄弟表現
 */

int depth(int m) {
  int d = 0;
  while (true) {
    if (nodes[m].parent != nil) {
      d++;
      m = nodes[m].parent;
    } else
      break;
  }
  return d;
}

string type(int m) {
  if (nodes[m].parent == nil) {
    return "root";
  } else if (nodes[m].left != nil) {
    return "internal node";
  } else {
    return "leaf";
  }
}

int main() {
  cin >> N;
  nodes = new Node[N];

  for (int k = 0; k < N; ++k) {
    nodes[k].left = nodes[k].right = nodes[k].parent = nil;
  }

  for (int i = 0; i < N; ++i) {
    int d;
    cin >> nodes[i].id >> d;
    int l;
    for (int j = 0; j < d; ++j) {
      int c;
      cin >> c;
      if (j == 0)
        nodes[i].left = c;
      else
        nodes[l].right = c;

      l = c;
      nodes[c].parent = i;
    }
  }

  for (int m = 0; m < N; ++m) {
    cout << "node " << m << ": parent = " << nodes[m].parent
         << ", depth = " << depth(m) << ", " << type(m);
    int i = nodes[m].left;
    if (nodes[m].left == nil) {
      cout << ", []" << endl;
      continue;
    }
    cout << ", [";
    while (true) {
      cout << i;
      if (nodes[i].right != nil) {
        cout << ", ";
        i = nodes[i].right;
      } else
        break;
    }
    cout << "]" << endl;
  }
  return 0;
}
Problem p02279 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
#define MAX 100005
#define NIL -1

struct Node {
  int p, l, r;
};

Node T[MAX];
int n, D[MAX];

void print(int u) {
  cout << "node " << u << ": ";
  cout << "parent = " << T[u].p << ", ";
  cout << "depth = " << D[u] << ", ";
  if (T[u].p == NIL)
    cout << "root, ";
  else if (T[u].l == NIL)
    cout << "leaf, ";
  else
    cout << "internal node, ";

  cout << "[";

  for (int i = 0, c = T[u].l; c != NIL; i++, c = T[c].r) {
    if (i)
      cout << ", ";
    cout << c;
  }
  cout << "]" << endl;
}

void rec(int u, int p) {
  D[u] = p;
  if (T[u].r != NIL)
    rec(T[u].r, p);
  if (T[u].l != NIL)
    rec(T[u].l, p + 1);
}

int main() {
  int i, j, d, v, c, l, r;
  cin >> n;
  for (int i = 0; i < n; i++)
    T[i].p = T[i].l = T[i].r = NIL;

  for (i = 0; i < n; i++) {
    cin >> v >> d;
    for (j = 0; j < d; j++) {
      cin >> c;
      if (j == 0)
        T[v].l = c;
      else
        T[l].r = c;
      l = c;
      T[c].p = v;
    }
  }
  for (i = 0; i < n; i++) {
    if (T[i].p == NIL)
      r = i;
  }

  rec(r, 0);

  for (i = 0; i < n; i++)
    print(i);

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
#define MAX 100005
#define NIL -1

struct Node {
  int p, l, r;
};

Node T[MAX];
int n, D[MAX];

void print(int u) {
  cout << "node " << u << ": ";
  cout << "parent = " << T[u].p << ", ";
  cout << "depth = " << D[u] << ", ";
  if (T[u].p == NIL)
    cout << "root, ";
  else if (T[u].l == NIL)
    cout << "leaf, ";
  else
    cout << "internal node, ";

  cout << "[";

  for (int i = 0, c = T[u].l; c != NIL; i++, c = T[c].r) {
    if (i)
      cout << ", ";
    cout << c;
  }
  cout << "]" << endl;
}

void rec(int u, int p) {
  D[u] = p;
  if (T[u].r != NIL)
    rec(T[u].r, p);
  if (T[u].l != NIL)
    rec(T[u].l, p + 1);
}

int main() {
  int d, v, c, l, r;
  cin >> n;
  for (int i = 0; i < n; i++)
    T[i].p = T[i].l = T[i].r = NIL;

  for (int i = 0; i < n; i++) {
    cin >> v >> d;
    for (int j = 0; j < d; i++) {
      cin >> c;
      if (j == 0)
        T[v].l = c;
      else
        T[l].r = c;
      l = c;
      T[c].p = v;
    }
  }
  for (int i = 0; i < n; i++) {
    if (T[i].p == NIL)
      r = i;
  }

  rec(r, 0);

  for (int i = 0; i < n; i++)
    print(i);

  return 0;
}
Problem p02279 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>
#include <vector>
using namespace std;
struct tree {
  int p;
  int pos;
  vector<int> sons;
  bool root;
  bool leaf;
};
tree map[100000];
void build(int now) {
  for (int i = 0; i < map[now].sons.size(); i++) {
    map[map[now].sons[i]].pos = map[now].pos + 1;
    map[map[now].sons[i]].p = now;
    build(map[now].sons[i]);
  }
}
int main() {
  int n, l, k, r;
  scanf("%d", &n);
  for (int i = 0; i < n; i++)
    map[i].root = true;
  for (int i = 0; i < n; i++) {
    scanf("%d%d", &l, &k);
    if (k == 0)
      map[l].leaf = true;
    else
      map[l].leaf = false;
    for (int j = 0; j < k; j++) {
      scanf("%d", &r);
      map[l].sons.push_back(r);
      map[r].root = false;
    }
  }
  for (int i = 0; i < n; i++)
    if (map[i].root) {
      map[i].p = -1;
      map[i].pos = 0;
      build(i);
    }
  for (int i = 0; i < n; i++) {
    printf("node %d: parent = %d, depth = %d, ", i, map[i].p, map[i].pos);
    if (map[i].root)
      printf("root, [");
    else if (map[i].leaf)
      printf("leaf, [");
    else
      printf("internal node, [");
    if (!map[i].leaf) {
      printf("%d", map[i].sons[0]);
      for (int j = 1; j < map[i].sons.size(); j++)
        printf(", %d", map[i].sons[j]);
    }
    printf("]\\n");
  }
}

Error: 0

Fixed submission:

#include <algorithm>
#include <stdio.h>
#include <vector>
using namespace std;
struct tree {
  vector<int> sons;
  int pos;
  int p;
};
tree map[100000];
void build(int now) {
  for (int i = 0; i < map[now].sons.size(); i++)
    if (map[now].sons[i] != map[now].p) {
      map[map[now].sons[i]].p = now;
      map[map[now].sons[i]].pos = map[now].pos + 1;
      build(map[now].sons[i]);
    }
}
int main() {
  int n, r, k, l, top;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d%d", &l, &k);
    if (i == 0)
      top = l;
    for (int j = 0; j < k; j++) {
      scanf("%d", &r);
      map[l].sons.push_back(r);
    }
  }
  map[top].pos = 0;
  map[top].p = -1;
  build(top);
  for (int i = 0; i < n; i++) {
    printf("node %d: parent = %d, depth = %d, ", i, map[i].p, map[i].pos);
    sort(map[i].sons.begin(), map[i].sons.end());
    if (i == top) {
      printf("root, [%d", map[i].sons[0]);
      for (int j = 1; j < map[i].sons.size(); j++)
        printf(", %d", map[i].sons[j]);
      printf("]\\n");
    } else if (map[i].sons.size() > 0) {
      printf("internal node, [%d", map[i].sons[0]);
      for (int j = 1; j < map[i].sons.size(); j++)
        printf(", %d", map[i].sons[j]);
      printf("]\\n");
    } else
      printf("leaf, []\\n");
  }
}
Problem p02279 (C++) — buggy submission, verdict: Runtime Error

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

using namespace std;

#define MAX 100000
#define NIL -1

struct Node {
  int parent, left, right;
};

Node T[MAX];

int depth(int i) {
  int count = 0;
  int c = i;
  while (T[c].parent != NIL) {
    c = T[c].parent;
    count++;
  }
  return count;
}

string nodeType(int i) {
  if (T[i].parent == NIL) {
    return "root";
  } else if (T[i].left == NIL) {
    return "leaf";
  } else {
    return "internal node";
  }
}

void printNodeChild(int i) {
  int c = T[i].left;

  while (c != NIL) {
    cout << c;
    c = T[c].right;

    if (c != NIL) {
      cout << ", ";
    }
  }
}

void printNodeInfo(int i) {
  cout << "node " << i << ": ";
  cout << "parent = " << T[i].parent << ",";
  cout << " depth = " << depth(i) << ",";
  cout << " " << nodeType(i) << ",";
  cout << " [";
  printNodeChild(i);
  cout << "]";

  cout << endl;
}

int main() {
  int n;

  cin >> n;

  for (int i = 0; i < n; i++) {
    T[i].parent = T[i].left = T[i].right = NIL;
  }

  for (int i = 0; i < n; i++) {
    int id, k, l;

    cin >> id >> k;

    for (int j = 0; j < k; j++) {
      int c;
      cin >> c;
      if (j == 0) {
        T[id].left = c;
      } else {
        T[l].right = c;
      }
      l = c;
      T[c].parent = id;
    }
  }

  int root = 0;

  for (int i = 0; i < n; i++) {
    if (T[i].parent == NIL) {
      root = i;
    }
  }

  for (int i = 0; i < n; i++) {
    printNodeInfo(i);
  }

  // cout << root << endl;

  return 0;
}


Error: 0

Fixed submission:

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

using namespace std;

#define MAX 10000
#define NIL -1

struct Node {
  int parent, left, right;
};

Node T[MAX];

int depth(int i) {
  int count = 0;
  int c = i;
  while (T[c].parent != NIL) {
    c = T[c].parent;
    count++;
  }
  return count;
}

string nodeType(int i) {
  if (T[i].parent == NIL) {
    return "root";
  } else if (T[i].left == NIL) {
    return "leaf";
  } else {
    return "internal node";
  }
}

void printNodeChild(int i) {
  int c = T[i].left;

  while (c != NIL) {
    cout << c;
    c = T[c].right;

    if (c != NIL) {
      cout << ", ";
    }
  }
}

void printNodeInfo(int i) {
  cout << "node " << i << ": ";
  cout << "parent = " << T[i].parent << ",";
  cout << " depth = " << depth(i) << ",";
  cout << " " << nodeType(i) << ",";
  cout << " [";
  printNodeChild(i);
  cout << "]";

  cout << endl;
}

int main() {
  int n;

  cin >> n;

  for (int i = 0; i < n; i++) {
    T[i].parent = T[i].left = T[i].right = NIL;
  }

  for (int i = 0; i < n; i++) {
    int id, k, l;

    cin >> id >> k;

    for (int j = 0; j < k; j++) {
      int c;
      cin >> c;
      if (j == 0) {
        T[id].left = c;
      } else {
        T[l].right = c;
      }
      l = c;
      T[c].parent = id;
    }
  }

  int root = 0;

  for (int i = 0; i < n; i++) {
    if (T[i].parent == NIL) {
      root = i;
    }
  }

  for (int i = 0; i < n; i++) {
    printNodeInfo(i);
  }

  // cout << root << endl;

  return 0;
}
Problem p02279 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define N 100005
#define INF (1 << 30)
typedef long long ll;
using namespace std;

vector<int> child[N];
int parent[N];
int GetDepth(int idx) {
  int ret = 0;
  while (parent[idx] != -1) {
    ++ret;
    idx = parent[idx];
  }
  return ret;
}
const char *str[3] = {"root", "internal node", "leaf"};
int main() {
  int n;
  cin >> n;
  fill(parent, parent + n, -1);
  int id, k, c;
  for (int i = 0; i < n; ++i) {
    cin >> id >> k;
    for (int j = 0; j < k; ++j) {
      cin >> c;
      parent[c] = id;
      child[id].push_back(c);
    }
  }
  for (int i = 0; i < n; ++i) {
    int depth = GetDepth(i);
    int status;
    if (depth == 0)
      status = 0;
    else if (child[i].size()) {
      status = 1;
      sort(child[i].begin(), child[i].end());
    } else
      status = 2;
    printf("node %d: parent = %d, depth = %d, %s, ", i, parent[i], depth,
           str[status]);
    printf("[");
    for (int j = 0; j < child[i].size(); ++j) {
      if (j)
        printf(", ");
      printf("%d", child[i][j]);
    }
    printf("]\\n");
  }
  return 0;
}

Error: -11

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define N 100005
#define INF (1 << 30)
typedef long long ll;
using namespace std;

vector<int> child[N];
int parent[N];
int GetDepth(int idx) {
  int ret = 0;
  while (parent[idx] != -1) {
    ++ret;
    idx = parent[idx];
  }
  return ret;
}
const char *str[3] = {"root", "internal node", "leaf"};
int main() {
  freopen("in.txt", "r", stdin);
  freopen("out.txt", "w", stdout);
  int n;
  cin >> n;
  fill(parent, parent + n, -1);
  int id, k, c;
  for (int i = 0; i < n; ++i) {
    cin >> id >> k;
    for (int j = 0; j < k; ++j) {
      cin >> c;
      parent[c] = id;
      child[id].push_back(c);
    }
  }
  for (int i = 0; i < n; ++i) {
    int depth = GetDepth(i);
    int status;
    if (depth == 0)
      status = 0;
    else if (child[i].size()) {
      status = 1;
      sort(child[i].begin(), child[i].end());
    } else
      status = 2;
    printf("node %d: parent = %d, depth = %d, %s, ", i, parent[i], depth,
           str[status]);
    printf("[");
    for (int j = 0; j < child[i].size(); ++j) {
      if (j)
        printf(", ");
      printf("%d", child[i][j]);
    }
    printf("]\\n");
  }
  return 0;
}