stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include <cstdio>

#include <vector>

#include <string>

using namespace std;



struct Node

{

  int id;

  int parent;

  vector<int> children;

};



int getDepth(Node t[], Node n)

{

  int count = 0;

  Node node = n;

  while (node.parent != -1)

  {

    count++;

    node = t[node.parent];

  }

  return count;

}



int main()

{

  int n;

  scanf("%d", &n);



  Node tree[100000];

  for (int i = 0; i < 100000; i++)

    tree[i] = {-100, -1, {}};



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

  {

    int id, k, tmp;

    scanf("%d%d", &id, &k);

    tree[id].id = id;

    for (int j = 0; j < k; j++)

    {

      scanf("%d", &tmp);

      tree[id].children.push_back(tmp);

      tree[tmp].parent = id;

    }

  }



  for (int i = 0; i < 100000; i++)

  {

    Node node = tree[i];

    if (node.id != -100)

    {

      string type = node.parent == -1 ? "root" : (node.children.size() == 0 ? "leaf" : "internal node");

      printf("node %d: parent = %d, depth = %d, %s, [",

             node.id, node.parent, getDepth(tree, node), type.c_str());

      int size = node.children.size();

      for (int j = 0; j < size; j++)

      {

        if (j != 0)

          printf(", ");

        printf("%d", node.children[j]);

      }

      printf("]\n");

    }

  }

  return 0;

}

// Faster C++ solution for the same problem (measured speedup: 28.841551568716106x):
#include <cstdio>

using namespace std;

#define MAX 100001

#define NIL -1



struct Node

{

  int parent, left, right;

};



Node TREE[MAX];

int n, DEP[MAX];



void print(int u)

{

  int i, c;

  printf("node %d: ", u);

  printf("parent = %d, ", TREE[u].parent);

  printf("depth = %d, ", DEP[u]);



  if (TREE[u].parent == NIL)

    printf("root, [");

  else if (TREE[u].left == NIL)

    printf("leaf, [");

  else

    printf("internal node, [");



  for (int i = 0, c = TREE[u].left; c != NIL; i++, c = TREE[c].right)

  {

    if (i)

      printf(", ");

    printf("%d", c);

  }

  printf("]\n");

}



void setDepth(int u, int p)

{

  DEP[u] = p;

  if (TREE[u].right != NIL)

    setDepth(TREE[u].right, p);

  if (TREE[u].left != NIL)

    setDepth(TREE[u].left, p + 1);

}



int main()

{

  int n, child;

  scanf("%d", &n);



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

    TREE[i].parent = TREE[i].left = TREE[i].right = NIL;



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

  {

    int id, k, childId;

    scanf("%d%d", &id, &k);

    for (int j = 0; j < k; j++)

    {

      scanf("%d", &childId);

      if (j == 0)

        TREE[id].left = childId;

      else

        TREE[child].right = childId;

      child = childId;

      TREE[childId].parent = id;

    }

  }



  int root;

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

    if (TREE[i].parent == NIL)

      root = i;



  setDepth(root, 0);



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

    print(i);



  return 0;

}
// Slower C++ solution:
#include <iostream>

#include <vector>

#include <string>



using namespace std;

typedef long long int llint;



struct Node {

	llint parent;

	llint depth;

	string state;

	vector<llint> children;

	Node():parent(-1),depth(0){

	}

};

struct faster_io{

	faster_io() {

		cin.tie(0);

		ios::sync_with_stdio(false);

	}

};



void set_depth(vector<Node> &Nodes, Node &node, int depth) {

	node.depth = depth;

	for (int i = 0; i < node.children.size(); i++) {

		set_depth(Nodes, Nodes[node.children[i]], depth + 1);

	}

}





int main() {

	llint const N_MAX = 100000;

	faster_io io;



	llint n;

	cin >> n;



	vector<Node> Nodes;

	Nodes.resize(N_MAX);



	for (llint i = 0; i < n; i++) {

		llint id, k;

		cin >> id >> k;

		Node &x = Nodes[id];

		for (llint j = 0; j < k; j++) {

			llint c;

			cin >> c;

			x.children.push_back(c);

			Nodes[c].parent = id;

		}

	}



	Node root;

	for (llint i = 0; i < n; i++) {

		Node &x = Nodes[i];

		if (x.parent == -1) {

			x.state = "root";

			root = x;

		}

		else if (x.children.size() == 0) {

			x.state = "leaf";

		}

		else {

			x.state = "internal node";

		}

	}



	set_depth(Nodes, root, 0);



	for (llint i = 0; i < n; i++) {

		Node x = Nodes[i];

		cout << "node " << i

			<< ": parent = " << x.parent

			<< ", depth = " << x.depth

			<< ", " << x.state

			<< ", [";

		for (llint j = 0; j < x.children.size(); j++)	{

			if (j != x.children.size() - 1) cout << x.children[j] << ", ";

			else cout << x.children[j];

		}

		cout << "]\n";

	}

}

// Faster C++ solution for the same problem (measured speedup: 47.125092823678486x):
#include <cstdio>

 

#define NIL -1

const int MAX_N = 100000 + 5;

 

struct Node {

  int p, lc, rs;

};

 

Node node[MAX_N];

int n;

int id, k, c;

int d[MAX_N];

 

void setDepth(int i, int num) {

  d[i] = num;

  if (node[i].rs != NIL) setDepth(node[i].rs, num);

  if (node[i].lc != NIL) setDepth(node[i].lc, num + 1);

}

 

int main() {

  scanf("%d", &n);

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

    node[i].p = node[i].lc = node[i].rs = NIL;

  }

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

    scanf("%d %d", &id, &k);

    int ls;

    for (int j = 0; j < k; j++) {

      scanf("%d", &c);

      node[c].p = id;

      if (j == 0) node[id].lc = c;

      else node[ls].rs = c;

      ls = c;

    }

  }

 

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

    if (node[i].p == NIL) {

      setDepth(i, 0);

      break;

    }

  }

   

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

    printf("node %d: parent = %d, depth = %d, ", i, node[i].p, d[i]);

    if (node[i].p == NIL) printf("root, ");

    else if (node[i].lc == NIL) printf("leaf, ");

    else printf("internal node, ");

    printf("[");

    for (int j = 0, c = node[i].lc; c != NIL; j++, c = node[c].rs) {

      if (j) printf(", ");

      printf("%d", c);

    }

    printf("]\n");

  }

  return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>

#define N 100000

using namespace std;



int child[N][20];

int parent[N];

int depth[N];

int k[N];

int root;



char str[3][20] = {"root","internal node","leaf"};



void pr(int id){

  int type;

  if(parent[id] == -1) type = 0;

  else if(k[id] > 0) type = 1;

  else if(k[id] == 0) type = 2;



  

  printf("node %d: parent = %d, depth = %d, %s, [", id, parent[id], depth[id], str[type]);

  for(int i=0;i<k[id];i++){

    if(i)printf(", ");

    printf("%d",child[id][i]);

  }

  printf("]\n");

}



void dfs(int id,int dep){

  depth[id] = dep;

  for(int i=0;i<k[id];i++)dfs(child[id][i],dep+1);

}



int main(){

  int n;

  cin>>n;

  memset(parent,-1,sizeof(parent));

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

    cin>>id;

    cin>>k[id];

    for(int j=0;j<k[id];j++){

      cin>>child[id][j];

      parent[ child[id][j] ] = id;

    }

  }

  

  for(int i=0;i<n;i++) if(parent[i] == -1) root = i;

  dfs(root,0);

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



  return 0;

}

// Faster C++ solution for the same problem (measured speedup: 7.153058883707279x):
#include<stdio.h>

#define MAX 100005

#define NIL -1

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

typedef struct Node_struct Node;

Node T[MAX];

int n, D[MAX];



void print(int u){

  int i, c;

  printf("node %d: parent = %d, depth = %d, ", u, T[u].p, D[u]);

  if(T[u].p == NIL) printf("root, ");

  else if(T[u].l == NIL) printf("leaf, ");

  else printf("internal node, ");

  printf("[");

  for (i =0, c = T[u].l; c != NIL; i++, c = T[c].r){

    if(i) printf(", ");

    printf("%d", c);

  }

  printf("]\n");

}



void rec(int u, int p){

  D[u] = p;

  if(T[u].l != NIL) rec(T[u].l, p + 1);

  if(T[u].r != -1) rec(T[u].r, p);

}



int main(){

  int i, j, k;

  int N;

  int id, sib, child;

  int root = NIL;

  scanf("%d", &N);

  for(i=0;i<N;i++) T[i].p = T[i].l = T[i].r = NIL;

  

  for(i=0; i<N; i++){

    scanf("%d %d", &id, &k);

    for(j =0, sib= NIL; j<k; j++){

      scanf("%d", &child);

      T[child].p = id;

      if(j == 0) T[id].l = child;

      else T[sib].r = child;

      sib = child;

    }

  }



  for(i=0; i<N; i++){

    if(T[i].p == -1) root = i;

  }

  rec(root, 0);

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

  

  return 0;

}
// Slower C++ solution:
#include <cstdio>

#include <vector>

#pragma warning(disable : 4996)

using namespace std;

int n, id, c, p[100009], d[100009]; vector<int> child[100009]; bool vis[100009];

void rec(int pos) {

	vis[pos] = true;

	for (int i : child[pos]) rec(i);

}

void solve(int pos) {

	for (int i : child[pos]) {

		d[i] = d[pos] + 1;

		p[i] = pos;

		solve(i);

	}

}

int main() {

	scanf("%d", &n);

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

		scanf("%d%d", &id, &c);

		child[id].resize(c);

		for (int j = 0; j < c; j++) {

			scanf("%d", &child[id][j]);

		}

	}

	int root = -1;

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

		if (!vis[i]) {

			root = i;

			rec(i);

		}

	}

	solve(root); p[root] = -1;

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

		printf("node %d: parent = %d, depth = %d, %s, [", i, p[i], d[i], (i == root ? "root" : (child[i].size() ? "internal node" : "leaf")));

		for (int j = 0; j < child[i].size(); j++) {

			if (j) printf(", ");

			printf("%d", child[i][j]);

		}

		printf("]\n");

	}

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 18.47456532850315x):
#include <cstdio>

// ----- very fast input/output ----- //

int read_int() {

	char ch = getchar_unlocked();

	int res = 0;

	while('0' <= ch && ch <= '9') {

		res = res * 10 + ch - '0';

		ch = getchar_unlocked();

	}

	return res;

}

void print_str(const char* str) {

	while(*str != '\0') {

		putchar_unlocked(*str);

		++str;

	}

}

char buf[1024];

void print_int(int x) {

	if(x < 0) {

		putchar_unlocked('-');

		x *= -1;

	}

	int ptr = 0, g;

	do {

		g = x / 10;

		buf[ptr++] = x - g * 10;

		x = g;

	} while(x > 0);

	while(ptr--) {

		putchar_unlocked(buf[ptr] + '0');

	}

}

// ----- main part ----- //

int N, sep[102400], dst[102400], depth[102400], par[102400];

int inputs[307200];

void find_depth(int pos) {

	for(int i = sep[pos]; i < sep[pos + 1]; ++i) {

		depth[dst[i]] = depth[pos] + 1;

		find_depth(dst[i]);

	}

}

int main() {

	// #1. read input

	N = read_int();

	for(int i = 0; i < 3 * N - 1; ++i) {

		inputs[i] = read_int();

	}

	// #2. construct tree

	int curpos = 0;

	for(int i = 0; i < N; ++i) {

		sep[inputs[curpos] + 1] = inputs[curpos + 1];

		curpos += inputs[curpos + 1] + 2;

	}

	for(int i = 0; i < N; ++i) {

		sep[i + 1] += sep[i];

	}

	curpos = 0;

	int root = 0;

	for(int i = 0; i < N; ++i) {

		int id = inputs[curpos];

		for(int j = sep[id]; j < sep[id + 1]; ++j) {

			dst[j] = inputs[curpos + j - sep[id] + 2];

			par[dst[j]] = id;

			root ^= dst[j];

		}

		root ^= i;

		curpos += inputs[curpos + 1] + 2;

	}

	par[root] = -1;

	find_depth(root);

	// step #3. print the answer

	for(int i = 0; i < N; ++i) {

		print_str("node ");

		print_int(i);

		print_str(": parent = ");

		print_int(par[i]);

		print_str(", depth = ");

		print_int(depth[i]);

		print_str(i == root ? ", root, [" : (sep[i] == sep[i + 1] ? ", leaf, [" : ", internal node, ["));

		for(int j = sep[i]; j < sep[i + 1]; ++j) {

			if(j != sep[i]) print_str(", ");

			print_int(dst[j]);

		}

		print_str("]\n");

	}

	return 0;

}
// Slower C++ solution:
#include <iostream>

#include <stdio.h>

#include <vector>

using namespace std;



struct Node{

	int parent;

	int depth;

	vector<int> children;

};



void solve(vector<struct Node> &node, int x){

	for(int i=0;i<node[x].children.size();i++){

		node[node[x].children[i]].depth += node[x].depth + 1;

		solve(node, node[x].children[i]);

	}

}



void printNode(vector<struct Node> node, int n){

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

		cout<<"node "<<i<<": parent = "<<node[i].parent<<", depth = "<<node[i].depth<<", ";

		

		if(node[i].parent == -1)

			cout<<"root";

		else if(node[i].children.size() == 0)

			cout<<"leaf";

		else

			cout<<"internal node";



		cout<<", [";

		for(int j=0;j<node[i].children.size();j++){

			cout<<node[i].children[j];

			if(j != node[i].children.size()-1)

				cout<<", ";

		}

		cout<<"]"<<endl;

	}

}



int main(){

	int n, id, k, c, x;

	vector<struct Node> node(100000);



	cin>>n;

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

		node[i].parent = -1;

		node[i].depth = 0;

	}



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

		cin>>id>>k;

		

		for(int j=0;j<k;j++){

			cin>>c;

			node[id].children.push_back(c);

			node[c].parent = id;

		}

	}



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

		if(node[i].parent == -1)

			x = i;



	solve(node, x);

	printNode(node, n);

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 8.365889197633305x):
// ALDS1_7_A

#include <iostream>

#include <vector>

using namespace std;



struct Node {

	int parent;

	int depth;

	vector<int> children;

};



void cal_depth(vector<Node> &Tree, int p) {

	if (Tree[p].parent != -1)

		Tree[p].depth = Tree[Tree[p].parent].depth + 1;



	for (int i = 0; i < Tree[p].children.size(); i++)

		cal_depth(Tree, Tree[p].children[i]);

}



void printTree(vector<Node> Tree) {

	for (int i = 0; i < Tree.size(); i++) {

		cout <<"node "<< i << ": parent = " << Tree[i].parent << ", depth = " << Tree[i].depth << ", ";

		

		if (Tree[i].parent == -1)

			cout << "root, ";

		else if (Tree[i].children.size() == 0)

			cout << "leaf, ";

		else

			cout << "internal node, ";

		

		cout << "[";

		for (int j = 0; j < Tree[i].children.size(); j++) {

			cout << Tree[i].children[j];

			if (j != Tree[i].children.size() - 1)

				cout << ", ";

		}

		cout << "]" << endl;

	}

}



int main() {

	

	int n, id, c, k, root;

	cin >> n;



	vector<Node> Tree;



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

		Node node;

		node.parent = -1;

		node.depth = 0;

		Tree.push_back(node);

	}



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

		cin >> id >> k;

		

		for (int j = 0; j < k; j++) {

			cin >> c;

			Tree[c].parent = id;

			Tree[id].children.push_back(c);

		}

	}



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

		if (Tree[i].parent == -1)

			root = i;

	}



	cal_depth(Tree, root);



	printTree(Tree);



	return 0;

}
// Slower C++ solution:
#include <iostream>

#include <queue>

#include <vector>

#include <utility>



#define rep(i, n) REP(i, 0, n)

#define REP(i, a, n) for(int i = a ; i < (int)n ; i++)

#define pb push_back

#define NIL -1

#define MAX 100001



using namespace std;



struct Node{

  int id;

  int parent;

  vector<int> child;

  int depth;

  

  void addChild(int c){

    child.pb(c);

  }

    

 void print(){

    cout << "node " << id << ": ";

    cout << "parent = " << parent << ", ";

    cout << "depth = " << depth << ", ";

    cout << (parent == -1?"root":child.size()==0?"leaf":"internal node") << ", ";

    cout << "[";

    if(child.size() != 0){

      rep(i, child.size()-1){

    cout << child[i] << ", ";

      }

      cout << child[child.size()-1];

    }

      cout << "]" << endl;

 }

};



Node node[MAX];



void init(int n){

  rep(i, n){

    node[i].depth = NIL;

    node[i].parent = NIL;

    node[i].child.clear();    

  }

}



signed main(){

  int n;

  int id, k, c, root;

  cin >> n;

  init(n);

  

  root = NIL;



  rep(i, n){

    cin >> id >> k;

    node[id].id = id;

    rep(j, k){

      cin >> c;

      node[id].addChild(c);

      node[c].parent = id;

      node[c].depth = node[id].depth + 1;

    }

  }



  rep(i, n){

    if(node[i].parent == NIL){

      root = i;

      break;

    }

  }

  

  queue<pair<Node, int> > q;

  q.push(make_pair(node[root], -1));

  while(!(q.empty())){

    pair<Node, int> p = q.front(); q.pop();

    node[p.first.id].depth = p.second + 1;

    rep(i, p.first.child.size()){

      q.push(make_pair(node[p.first.child[i]], p.second + 1));

    }

  }

  

  rep(i, n){

    node[i].print();

  }

}

// Faster C++ solution for the same problem (measured speedup: 5.3177489069296975x):
#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); //もっとも左の子に自分の深さ+1を設定

  return 0;

}



int main(){

  int i,j,d,v,c,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;

    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;

}
// Slower C++ solution:
#include<iostream>

#include<cstdlib>

#include<string>

using namespace std;



int n;



struct node

{

	int id, pid, bid, k, d;

	int* cid;

	string type;

}N[100005];



void GetDepth(node& GN)

{

	GN.d = 0;

	node temp = GN;



	while (temp.pid != -1)

	{

		GN.d++;

		temp = N[temp.pid];

	}

}



void GetType(node& GN)

{

	if (GN.pid == -1)

		GN.type = "root";

	else if (GN.k == 0)

		GN.type = "leaf";

	else

		GN.type = "internal node";

}



void print()

{

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

	{

		cout << "node " << N[i].id << ": " << "parent = " << N[i].pid << ", " << "depth = " << N[i].d << ", " << N[i].type << ", " << "[";



		if (N[i].k != 0)

		{

			for (int j = 0; j < N[i].k - 1; j++)

				cout << N[i].cid[j] << ", ";

			cout << N[i].cid[N[i].k - 1];

		}



		cout << "]" << endl;

	}	

}



int main()

{

	ios::sync_with_stdio(false);

	cin.tie(0);



	int place;

	cin >> n;

	

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

		N[i].pid = -1;

	

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

	{

		cin >> place;

		N[place].id = place;

		cin >> N[place].k;



		if (N[place].k > 0)

			N[place].cid = (int*)malloc(sizeof(int) * N[place].k);



		for (int j = 0; j < N[place].k; j++)

		{

			cin >> N[place].cid[j];

			N[N[place].cid[j]].pid = N[place].id;

		}			

	}



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

		GetDepth(N[i]);



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

		GetType(N[i]);	



	print();



	return 0;

}






// Faster C++ solution for the same problem (measured speedup: 1.1251330586936952x):
#include<iostream>

#include<cstdlib>

#include<string>

using namespace std;



int n;



struct node

{

	int id, pid, k, d;

	int* cid;

	string type;

}N[100005];



void GetDepth(node& GN)

{

	GN.d = 0;

	node temp = GN;



	while (temp.pid != -1)

	{

		GN.d++;

		temp = N[temp.pid];

	}

}



void GetType(node& GN)

{

	if (GN.pid == -1)

		GN.type = "root";

	else if (GN.k == 0)

		GN.type = "leaf";

	else

		GN.type = "internal node";

}



void print()

{

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

	{

		cout << "node " << N[i].id << ": " << "parent = " << N[i].pid << ", " << "depth = " << N[i].d << ", " << N[i].type << ", " << "[";



		if (N[i].k != 0)

		{

			for (int j = 0; j < N[i].k - 1; j++)

				cout << N[i].cid[j] << ", ";

			cout << N[i].cid[N[i].k - 1];

		}



		cout << "]" << endl;

	}	

}



int main()

{

	ios::sync_with_stdio(false);

	cin.tie(0);



	int place;

	cin >> n;

	

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

		N[i].pid = -1;

	

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

	{

		cin >> place;

		N[place].id = place;

		cin >> N[place].k;



		if (N[place].k > 0)

			N[place].cid = (int*)malloc(sizeof(int) * N[place].k);



		for (int j = 0; j < N[place].k; j++)

		{

			cin >> N[place].cid[j];

			N[N[place].cid[j]].pid = N[place].id;

		}			

	}



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

		GetDepth(N[i]);



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

		GetType(N[i]);	



	print();



	return 0;

}
// Slower C++ solution:
#include<iostream>

#include<cstdlib>

#include<string>

using namespace std;



int n;



struct node

{

	int id, pid, bid, k, d;

	int* cid;

	string type;

}N[100005];



void GetDepth(node& GN)

{

	GN.d = 0;

	node temp = GN;



	while (temp.pid != -1)

	{

		GN.d++;

		temp = N[temp.pid];

	}

}



void GetType(node& GN)

{

	if (GN.pid == -1)

		GN.type = "root";

	else if (GN.k == 0)

		GN.type = "leaf";

	else

		GN.type = "internal node";

}



void print()

{

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

	{

		cout << "node " << N[i].id << ": " << "parent = " << N[i].pid << ", " << "depth = " << N[i].d << ", " << N[i].type << ", " << "[";



		if (N[i].k != 0)

		{

			for (int j = 0; j < N[i].k - 1; j++)

				cout << N[i].cid[j] << ", ";

			cout << N[i].cid[N[i].k - 1];

		}



		cout << "]" << endl;

	}	

}



int main()

{

	ios::sync_with_stdio(false);

	cin.tie(0);



	int place;

	cin >> n;

	

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

		N[i].pid = -1;

	

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

	{

		cin >> place;

		N[place].id = place;

		cin >> N[place].k;



		if (N[place].k > 0)

			N[place].cid = (int*)malloc(sizeof(int) * N[place].k);



		for (int j = 0; j < N[place].k; j++)

		{

			cin >> N[place].cid[j];

			N[N[place].cid[j]].pid = N[place].id;

		}			

	}



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

		GetDepth(N[i]);



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

		GetType(N[i]);	



	print();



	return 0;

}






// Faster C++ solution for the same problem (measured speedup: 1.1252637708530548x):
#include<iostream>

#include<cstdlib>

#include<string>

using namespace std;



int n;



struct node

{

	int id, pid, k, d;

	int* cid;

	string type;

}N[100005];



void GetDepth(node& GN)

{

	GN.d = 0;

	node temp = GN;



	while (temp.pid != -1)

	{

		GN.d++;

		temp = N[temp.pid];

	}

}



void GetType(node& GN)

{

	if (GN.pid == -1)

		GN.type = "root";

	else if (GN.k == 0)

		GN.type = "leaf";

	else

		GN.type = "internal node";

}



void print()

{

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

	{

		cout << "node " << N[i].id << ": " << "parent = " << N[i].pid << ", " << "depth = " << N[i].d << ", " << N[i].type << ", " << "[";



		if (N[i].k != 0)

		{

			for (int j = 0; j < N[i].k - 1; j++)

				cout << N[i].cid[j] << ", ";

			cout << N[i].cid[N[i].k - 1];

		}



		cout << "]" << endl;

	}	

}



int main()

{

	ios::sync_with_stdio(false);

	cin.tie(0);



	int place;

	cin >> n;

	

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

		N[i].pid = -1;

	

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

	{

		cin >> place;

		N[place].id = place;

		cin >> N[place].k;



		if (N[place].k > 0)

			N[place].cid = new int[N[place].k];



		for (int j = 0; j < N[place].k; j++)

		{

			cin >> N[place].cid[j];

			N[N[place].cid[j]].pid = N[place].id;

		}			

	}



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

		GetDepth(N[i]);



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

		GetType(N[i]);	



	print();



	return 0;

}