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

#include <iostream>
#include <vector>
using namespace std;

struct node {
  int parent, depth;
  vector<int> child;
};

vector<node> tree;

void dfs(int num) {
  if (tree[num].child.size() == 0)
    return;
  for (int i = 0; i < tree[num].child.size(); i++) {
    tree[tree[num].child[i]].depth = tree[num].depth + 1;
    dfs(tree[num].child[i]);
  }
}

int main() {
  int n, m, now, t;
  cin >> n;
  tree.resize(n);
  for (int i = 0; i < n; i++) {
    cin >> now >> m;
    vector<int> vec;
    for (int j = 0; j < m; j++) {
      cin >> t;
      vec.push_back(t);
    }
    tree[now] = {-1, 0, vec};
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < tree[i].child.size(); j++)
      tree[tree[i].child[j]].parent = i;
  }
  int par;
  for (int i = 0; i < n; i++) {
    if (tree[i].parent == -1)
      par = i;
  }
  dfs(par);
  for (int i = 0; i < n; i++) {
    cout << "node " << i << ": parent = " << tree[i].parent
         << ", depth = " << tree[i].depth;
    if (tree[i].parent == -1) {
      cout << ", root, [";
      if (tree[i].child.size() != 0)
        cout << tree[i].child[0];
      for (int j = 1; j < tree[i].child.size(); j++)
        cout << ", " << tree[i].child[j];
      cout << "]" << endl;
    } else if (tree[i].child.size() == 0)
      cout << ", leaf, []" << endl;
    else {
      cout << ", internal node, [" << tree[i].child[0];
      for (int j = 1; j < tree[i].child.size(); j++)
        cout << ", " << tree[i].child[j];
      cout << "]" << endl;
    }
  }
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#include <vector>
using namespace std;

struct node {
  int parent, depth;
  vector<int> child;
};

vector<node> tree;

void dfs(int num) {
  if (tree[num].child.size() == 0)
    return;
  for (int i = 0; i < tree[num].child.size(); i++) {
    tree[tree[num].child[i]].depth = tree[num].depth + 1;
    dfs(tree[num].child[i]);
  }
}

int main() {
  int n, m, now, t;
  cin >> n;
  tree.resize(n);
  for (int i = 0; i < n; i++) {
    cin >> now >> m;
    vector<int> vec;
    for (int j = 0; j < m; j++) {
      cin >> t;
      vec.push_back(t);
    }
    tree[now] = {-1, 0, vec};
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < tree[i].child.size(); j++)
      tree[tree[i].child[j]].parent = i;
  }
  int par;
  for (int i = 0; i < n; i++) {
    if (tree[i].parent == -1)
      par = i;
  }
  dfs(par);
  for (int i = 0; i < n; i++) {
    cout << "node " << i << ": parent = " << tree[i].parent
         << ", depth = " << tree[i].depth;
    if (tree[i].parent == -1) {
      cout << ", root, [" << tree[i].child[0];
      for (int j = 1; j < tree[i].child.size(); j++)
        cout << ", " << tree[i].child[j];
      cout << "]" << endl;
    } else if (tree[i].child.size() == 0)
      cout << ", leaf, []" << endl;
    else {
      cout << ", internal node, [" << tree[i].child[0];
      for (int j = 1; j < tree[i].child.size(); j++)
        cout << ", " << tree[i].child[j];
      cout << "]" << endl;
    }
  }
  return 0;
}
Problem p02279 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <vector>
using namespace std;
struct Node {
  int parent = -2;
  string type;
  vector<int> children;
};
int main() {
  int n;
  cin >> n;
  Node node[n];
  for (int i = 0; i < n; i++) {
    int id, k;
    cin >> id >> k;
    if (k == 0) { // no children
      node[id].type = "leaf";
    }
    if (node[id].parent == -2) {
      node[id].parent = -1;
    }
    int cnt3 = 0;
    for (int j = 0; j < k; j++) {
      int c;
      cin >> c;
      node[c].parent = id;
      node[id].children.push_back(c);
      cnt3++;
    }
    node[id].children.push_back(-2);
  }
  for (int i = 0; i < n; i++) {
    cout << "node " << i << ": parent = " << node[i].parent;
    cout << ", depth = ";
    int tmp = i;
    int cnt = 0;
    while (node[tmp].parent != -1) {
      tmp = node[tmp].parent;
      cnt++;
    }
    cout << cnt << ", ";
    if (node[i].parent == -1) {
      cout << "root";
    } else if (node[i].type == "leaf") {
      cout << "leaf";
    } else {
      cout << "internal node";
    }
    cout << ", [";
    int cnt2 = 0;
    while (1) {
      if (node[i].children[cnt2] == -2) { // 最初に置かな最初の-2見逃す
        break;
      }
      if (cnt2) {
        cout << ", ";
      }
      cout << node[i].children[cnt2];
      cnt2++;
    }
    cout << "]" << endl;
  }
  return 0;
}


Error: -11

Fixed submission:

#include <iostream>
using namespace std;
struct Node {
  int parent = -2;
  string type;
  int children[11];
};
int main() {
  int n;
  cin >> n;
  Node node[100001];
  for (int i = 0; i < n; i++) {
    int id, k;
    cin >> id >> k;
    if (k == 0) { // no children
      node[id].type = "leaf";
    }
    if (node[id].parent == -2) {
      node[id].parent = -1;
    }
    int cnt3 = 0;
    for (int j = 0; j < k; j++) {
      int c;
      cin >> c;
      node[c].parent = id;
      node[id].children[cnt3] = c;
      cnt3++;
    }
    node[id].children[k] = -2;
  }
  for (int i = 0; i < n; i++) {
    cout << "node " << i << ": parent = " << node[i].parent;
    cout << ", depth = ";
    int tmp = i;
    int cnt = 0;
    while (node[tmp].parent != -1) {
      tmp = node[tmp].parent;
      cnt++;
    }
    cout << cnt << ", ";
    if (node[i].parent == -1) {
      cout << "root";
    } else if (node[i].type == "leaf") {
      cout << "leaf";
    } else {
      cout << "internal node";
    }
    cout << ", [";
    int cnt2 = 0;
    while (1) {
      if (node[i].children[cnt2] == -2) { // 最初に置かな最初の-2見逃す
        break;
      }
      if (cnt2) {
        cout << ", ";
      }
      cout << node[i].children[cnt2];
      cnt2++;
    }
    cout << "]" << endl;
  }
  return 0;
}
Problem p02279 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <vector>
using namespace std;

int n = 0, id = 0, k = 0;
vector<int> d, p;

int depth(int id) {
  if (p[id] == -1)
    return 0;
  else if (d[p[id]] != -1)
    return d[p[id]] + 1;
  else
    return depth(p[id]) + 1;
}

int main() {
  cin >> n;

  vector<vector<int>> c(n);

  for (int i = 0; i < n; i++) {
    p.push_back(-1);
    d.push_back(-1);
  }

  for (int i = 0; i < n; i++) {
    cin >> id >> k;

    for (int j = 0; j < k; j++) {
      int ct = 0;
      cin >> ct;
      c[id].push_back(ct);
      p[ct] = id;
    }
  }

  for (int i = 0; i < n; i++) {
    d[i] = depth(i);
  }

  for (int i = 0; i < n; i++) {
    cout << "node " << i << ": parent = " << p[i] << ", depth = " << d[i]
         << ", ";

    if (p[i] == -1)
      cout << "root, ";
    else if (c[i].size() == 0)
      cout << "leaf, ";
    else
      cout << "internal node, ";

    cout << "[";
    if (c[i].size() > 1) {
      for (unsigned int j = 0; j < c[i].size() - 1; j++)
        cout << c[i][j] << ", ";
    }
    if (c[i].size() >= 1)
      cout << c[i][c[i].size() - 1];

    cout << "]" << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <vector>
using namespace std;

int n = 0, id = 0, k = 0;
vector<int> d, p;

int depth(int id) {
  if (p[id] == -1)
    return 0;
  else if (d[p[id]] != -1)
    return d[p[id]] + 1;
  else
    return depth(p[id]) + 1;
}

int main() {
  cin >> n;

  vector<vector<int>> c(n);

  for (int i = 0; i < n; i++) {
    p.push_back(-1);
    d.push_back(-1);
  }

  for (int i = 0; i < n; i++) {
    cin >> id >> k;

    for (int j = 0; j < k; j++) {
      int ct = 0;
      cin >> ct;
      c[id].push_back(ct);
      p[ct] = i;
    }
  }

  for (int i = 0; i < n; i++) {
    d[i] = depth(i);
  }

  for (int i = 0; i < n; i++) {
    cout << "node " << i << ": parent = " << p[i] << ", depth = " << d[i]
         << ", ";

    if (d[i] == 0)
      cout << "root, ";
    else if (c[i].size() == 0)
      cout << "leaf, ";
    else
      cout << "internal node, ";

    cout << "[";
    if (c[i].size() > 1) {
      for (unsigned int j = 0; j < c[i].size() - 1; j++)
        cout << c[i][j] << ", ";
    }
    if (c[i].size() >= 1)
      cout << c[i][c[i].size() - 1];

    cout << "]" << endl;
  }

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

#include <stdio.h>
#include <stdlib.h>
#define N 1000000

typedef struct node {
  int p;
  int right;
  int left;
} Node;

int main() {

  int n, i, j, l, c, k, id, P, depth, r;
  Node a[N], tmp;

  scanf("%d", &n);

  for (i = 0; i < n; i++) {
    a[i].p = -1;
    a[i].right = -1;
    a[i].left = -1;
  }

  for (i = 0; i < n; i++) {
    scanf("%d%d", &id, &k);

    for (j = 0; j < k; j++) {
      scanf("%d", &c);
      if (j == 0)
        a[id].left = c;
      else
        a[r].right = c;
      a[c].p = id;
      r = c;
    }
  }

  for (i = 0; i < n; i++) {
    depth = 0;
    P = a[i].p;

    while (P != -1) {
      P = a[P].p;
      depth++;
    }

    if (a[i].p == -1) {
      printf("node %d: parent = %d, depth = %d, root, [", i, a[i].p, depth);
    } else if (a[i].left == -1)
      printf("node %d: parent = %d, depth = %d, leaf, [", i, a[i].p, depth);
    else
      printf("node %d: parent = %d, depth = %d, internal node, [", i, a[i].p,
             depth);

    P = a[i].left;
    if (P != -1)
      printf("%d", P);

    while (P != -1) {
      P = a[P].right;
      if (P != -1)
        printf(", %d", P);
    }
    printf("]\\n");
  }

  return 0;
}

Error: 0

Fixed submission:

#include <stdio.h>
#include <stdlib.h>
#define N 10000

typedef struct node {
  int p;
  int right;
  int left;
} Node;

int main() {

  int n, i, j, l, c, k, id, P, depth, r;
  Node a[N], tmp;

  scanf("%d", &n);

  for (i = 0; i < n; i++) {
    a[i].p = -1;
    a[i].right = -1;
    a[i].left = -1;
  }

  for (i = 0; i < n; i++) {
    scanf("%d%d", &id, &k);

    for (j = 0; j < k; j++) {
      scanf("%d", &c);
      if (j == 0)
        a[id].left = c;
      else
        a[r].right = c;
      a[c].p = id;
      r = c;
    }
  }

  for (i = 0; i < n; i++) {
    depth = 0;
    P = a[i].p;

    while (P != -1) {
      P = a[P].p;
      depth++;
    }

    if (a[i].p == -1) {
      printf("node %d: parent = %d, depth = %d, root, [", i, a[i].p, depth);
    } else if (a[i].left == -1)
      printf("node %d: parent = %d, depth = %d, leaf, [", i, a[i].p, depth);
    else
      printf("node %d: parent = %d, depth = %d, internal node, [", i, a[i].p,
             depth);

    P = a[i].left;
    if (P != -1)
      printf("%d", P);

    while (P != -1) {
      P = a[P].right;
      if (P != -1)
        printf(", %d", P);
    }
    printf("]\\n");
  }

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

#include <bits/stdc++.h>
/*#include<iostream>
#include<algorithm>
#include<climits>*/
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctype.h>
#include <stdio.h>
#include <string.h>
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define rep1(i, a, b) for (int i = a; i <= (b); ++i)
#define per(i, a, b) for (int i = a; i > (b); --i)
#define per1(i, a, b) for (int i = a; i >= (b); --i)
#define LL long long
#define inf 0x7f7f7f7f
#define N 100010
using namespace std;
struct node {
  int p, l, r;
};

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

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

  if (T[u].p == -1)
    printf("root, ");
  else if (T[u].l == -1)
    printf("leaf, ");
  else
    printf("internal node, ");

  printf("[");
  for (i = 0, c = T[u].l; c != -1; i++, c = T[c].r) {
    if (i)
      printf(", ");
    printf("%d", c);
  }
  printf("]\\n");
}

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;
  int n, v, d, c, r, l;
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    T[i].p = T[i].l = T[i].r = -1;
  }
  for (i = 0; i < n; i++) {
    scanf("%d %d", &v, &d);
    for (j = 0; j < d; j++) {
      scanf("%d", &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);
  }
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
/*#include<iostream>
#include<algorithm>
#include<climits>*/
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctype.h>
#include <stdio.h>
#include <string.h>
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define rep1(i, a, b) for (int i = a; i <= (b); ++i)
#define per(i, a, b) for (int i = a; i > (b); --i)
#define per1(i, a, b) for (int i = a; i >= (b); --i)
#define LL long long
#define inf 0x7f7f7f7f
#define N 1010
using namespace std;
struct node {
  int p, l, r;
};

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

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

  if (T[u].p == -1)
    printf("root, ");
  else if (T[u].l == -1)
    printf("leaf, ");
  else
    printf("internal node, ");

  printf("[");
  for (i = 0, c = T[u].l; c != -1; i++, c = T[c].r) {
    if (i)
      printf(", ");
    printf("%d", c);
  }
  printf("]\\n");
}

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;
  int n, v, d, c, r, l;
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    T[i].p = T[i].l = T[i].r = -1;
  }
  for (i = 0; i < n; i++) {
    scanf("%d %d", &v, &d);
    for (j = 0; j < d; j++) {
      scanf("%d", &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);
  }
}
Problem p02279 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <string>
#include <vector>
using namespace std;

typedef struct {
  int id;
  int parent;
  int depth;
  int numOfChild;
  string type;
  vector<int> children;

} Node;
int getDepth(Node nodes[], int n) {
  int depth = 0;
  Node now = nodes[n];
  while (now.parent != -1) {
    now = nodes[now.parent];
    depth++;
  }

  return depth;
}

void setDepth(Node nodes[], int n, int d) {
  nodes[n].depth = d;
  for (int i = 0; i < nodes[n].numOfChild; i++) {
    setDepth(nodes, nodes[n].children.at(i), d + 1);
  }
}
int main() {
  static Node node[100000 + 1];
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    node[i].depth = 0;
    node[i].parent = -1;
  }
  for (int i = 0; i < n; i++) {
    int id, k;
    cin >> id >> k;
    node[id].id = id;
    node[id].numOfChild = k;
    for (int j = 0; j < k; j++) {
      int c;
      cin >> c;
      node[id].children.push_back(c);
      node[c].parent = id;
      node[c].depth = node[id].depth + 1;
    }
  }
  int root;
  for (int i = 0; i < n; i++) {
    if (node[i].parent == -1) {
      root = i;
      node[i].type = "root";
    } else if (node[i].numOfChild > 0) {
      node[i].type = "internal node";
    } else {
      node[i].type = "leaf";
    }
  }
  setDepth(node, root, 0);
  for (int i = 0; i < n; i++) {
    cout << "node " << i << ": parent = " << node[i].parent
         << ", depth = " << node[i].depth << ", " << node[i].type << ", [";
    for (int j = 0; j < node[i].numOfChild; j++) {
      if (j == 0) {
        cout << node[i].children[j];
      } else {
        cout << ", " << node[i].children[j];
      }
    }

    cout << "]" << endl;
  }
}

Error: TLE

Fixed submission:

#include <iostream>
#include <string>
#include <vector>
using namespace std;

typedef struct {
  int id;
  int parent;
  int depth;
  int numOfChild;
  string type;
  vector<int> children;

} Node;
int getDepth(Node nodes[], int n) {
  int depth = 0;
  Node now = nodes[n];
  while (now.parent != -1) {
    now = nodes[now.parent];
    depth++;
  }

  return depth;
}
int main() {
  static Node node[100000 + 1];
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    node[i].depth = 0;
    node[i].parent = -1;
  }
  for (int i = 0; i < n; i++) {
    int id, k;
    cin >> id >> k;
    node[id].id = id;
    node[id].numOfChild = k;
    for (int j = 0; j < k; j++) {
      int c;
      cin >> c;
      node[id].children.push_back(c);
      node[c].parent = id;
      node[c].depth = node[id].depth + 1;
    }
  }

  for (int i = 0; i < n; i++) {
    if (node[i].parent == -1) {
      node[i].type = "root";
    } else if (node[i].numOfChild > 0) {
      node[i].type = "internal node";
    } else {
      node[i].type = "leaf";
    }
  }

  for (int i = 0; i < n; i++) {
    cout << "node " << i << ": parent = " << node[i].parent
         << ", depth = " << getDepth(node, i) << ", " << node[i].type << ", [";
    for (int j = 0; j < node[i].numOfChild; j++) {
      if (j == 0) {
        cout << node[i].children[j];
      } else {
        cout << ", " << node[i].children[j];
      }
    }

    cout << "]" << endl;
  }
}
Problem p02279 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#include <tuple>

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
const int INF = 1e9;

using namespace std;

struct node {
  vector<int> child;
  int parent;
  int depth;
};

node n[100000];

int main() {
  int v;
  cin >> v;
  REP(i, v) {
    n[i].parent = -1;
    n[i].depth = 0;
  }
  REP(i, v) {
    int x, children;
    cin >> x;
    cin >> children;
    REP(j, children) {
      int y;
      cin >> y;
      n[x].child.push_back(y);
      n[y].parent = x;
    }
  }

  REP(i, v) {
    node x = n[i];
    int count = 0;
    while (x.parent != -1) {
      count++;
      x = n[x.parent];
    }
    n[i].depth = count;
  }

  REP(i, v) {
    string str;
    if (n[i].depth == 0)
      str = "root";
    else if (n[i].child.empty())
      str = "leaf";
    else
      str = "internal node";
    cout << "node " << i << ": parent = " << n[i].parent
         << ", depth = " << n[i].depth << ", " << str << ", [";
    int j = 0;
    for (j; j + 1 < n[i].child.size(); j++) {
      cout << n[i].child[j] << ", ";
    }
    if (!n[i].child.empty())
      cout << n[i].child[j];
    cout << "]" << endl;
  }

  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
#include <tuple>

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
#define square(x) (x) * (x)
#define cube(x) (x) * (x) * (x)

const int INF = 1e9;

using namespace std;

struct node {
  vector<int> child;
  int parent;
  int depth;
};

node n[100000];

int main() {
  int v;
  cin >> v;
  REP(i, v) {
    n[i].parent = -1;
    n[i].depth = 0;
  }
  REP(i, v) {
    int x, children;
    cin >> x;
    cin >> children;
    REP(j, children) {
      int y;
      cin >> y;
      n[x].child.push_back(y);
      n[y].parent = x;
      n[y].depth += n[x].depth + 1;
    }
  }

  REP(i, v) {
    string str;
    if (n[i].depth == 0)
      str = "root";
    else if (n[i].child.empty())
      str = "leaf";
    else
      str = "internal node";
    cout << "node " << i << ": parent = " << n[i].parent
         << ", depth = " << n[i].depth << ", " << str << ", [";
    int j = 0;
    for (j; j + 1 < n[i].child.size(); j++) {
      cout << n[i].child[j] << " ";
    }
    if (str != "leaf")
      cout << n[i].child[j];
    cout << "]" << endl;
  }

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

#include <algorithm>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
using namespace std;

struct Node {
  string type;
  int depth;
  int parent = -1;
  vector<int> child;
};

int main() {
  int n;
  Node node[100000];
  queue<Node *> q;
  int depth = 0;

  cin >> n;
  for (int i = 0; i < n; i++) {
    int id, k;
    cin >> id >> k;
    for (int j = 0; j < k; j++) {
      int temp;
      cin >> temp;
      node[id].child.push_back(temp);
      node[temp].parent = id;
    }
  }

  for (int i = 0; i < n; i++) {
    if (node[i].parent == -1) {
      q.push(&node[i]);
      break;
    }
  }

  while (!q.empty()) {
    int size = q.size();
    for (int i = 0; i < size; i++) {

      if (q.front()->parent == -1) {
        q.front()->type = "root";
      } else if (q.front()->child.empty()) {
        q.front()->type = "leaf";
      } else {
        q.front()->type = "internal node";
      }

      for (int j = 0; j < q.front()->child.size(); j++) {
        q.push(&node[q.front()->child[j]]);
      }
      q.front()->depth = depth;
      q.pop();
    }
    depth++;
  }

  for (int i = 0; i < n; i++) {
    cout << "node " << i << ": parent = " << node[i].parent << ", ";
    cout << "depth = " << node[i].depth << ", ";
    cout << node[i].type << ", ";
    cout << "[";
    for (int j = 0; j < node[i].child.size(); j++) {
      cout << node[i].child[j];
      if (j < node[i].child.size() - 1) {
        cout << ", ";
      }
    }
    cout << "]" << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
using namespace std;

struct Node {
  string type;
  int depth;
  int parent = -1;
  vector<int> child;
};

int main() {
  int n;
  Node node[1000];
  queue<Node *> q;
  int depth = 0;

  cin >> n;
  for (int i = 0; i < n; i++) {
    int id, k;
    cin >> id >> k;
    for (int j = 0; j < k; j++) {
      int temp;
      cin >> temp;
      node[id].child.push_back(temp);
      node[temp].parent = id;
    }
  }

  for (int i = 0; i < n; i++) {
    if (node[i].parent == -1) {
      q.push(&node[i]);
      break;
    }
  }

  while (!q.empty()) {
    int size = q.size();
    for (int i = 0; i < size; i++) {

      if (q.front()->parent == -1) {
        q.front()->type = "root";
      } else if (q.front()->child.empty()) {
        q.front()->type = "leaf";
      } else {
        q.front()->type = "internal node";
      }

      for (int j = 0; j < q.front()->child.size(); j++) {
        q.push(&node[q.front()->child[j]]);
      }
      q.front()->depth = depth;
      q.pop();
    }
    depth++;
  }

  for (int i = 0; i < n; i++) {
    cout << "node " << i << ": parent = " << node[i].parent << ", ";
    cout << "depth = " << node[i].depth << ", ";
    cout << node[i].type << ", ";
    cout << "[";
    for (int j = 0; j < node[i].child.size(); j++) {
      cout << node[i].child[j];
      if (j < node[i].child.size() - 1) {
        cout << ", ";
      }
    }
    cout << "]" << endl;
  }

  return 0;
}