#include<cstdio>
#define MAX 30
#define NIL -1                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
struct Node
{
	int parent = NIL;
	int left = NIL;
	int right = NIL;
};

Node T[MAX];

//前序遍历
void preorder(int u)
{
	if(u == NIL)
		return;
	printf(" %d",u);
	preorder(T[u].left);
	preorder(T[u].right);
}
//中序遍历
void inorder(int u)
{
	if(u == NIL)
		return;
	inorder(T[u].left);
	printf(" %d",u);
	inorder(T[u].right);
}
//后序遍历
void postorder(int u)
{
	if(u == NIL)
		return;
	postorder(T[u].left);
	postorder(T[u].right);
	printf(" %d",u);
}

int main()
{
	int n;
	int id,l,r;
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
	{
		scanf("%d%d%d",&id,&l,&r);
		T[id].left = l;
		T[id].right = r;
		if(l != NIL) T[l].parent = id;
		if(r != NIL) T[r].parent = id;
	}
	int root;
	for(int i=0; i<n; i++)
		if(T[i].parent == NIL)
			root = i;
	
	//Output
	printf("Preorder\n");
	preorder(root);

	printf("\nInorder\n");
	inorder(root);

	printf("\nPostorder\n");
	postorder(root);

	printf("\n");
}



Measured memory_bytes: 2740