<Problem>
https://oj.vnoi.info/problem/bintree
#include <iostream>
#include <vector>
using namespace std;
#define MAX 50001
int n;
int node[MAX];
int c[MAX];
vector <int> arr;
void postOrder(int preOLeft, int preORight, int inOLeft, int inORight) {
if (preOLeft > preORight) return;
int rootNodeIndex = preOLeft;
arr.push_back(node[rootNodeIndex]);
if (preOLeft == preORight) return;
else {
int numOfNodeToTheLeft = c[node[rootNodeIndex]] - inOLeft;
int numOfNodeToTheRight = inORight - c[node[rootNodeIndex]];
postOrder(preOLeft + numOfNodeToTheLeft + 1, preORight, c[node[rootNodeIndex]] + 1, inORight);
postOrder(preOLeft + 1, preORight - numOfNodeToTheRight, inOLeft, c[node[rootNodeIndex]] - 1);
}
}
int main() {
cin >> n;
for (int i = 1; i <= n; i++) cin >> node[i];
for (int i = 1; i <= n; i++) {
int x;
cin >> x;
c[x] = i;
}
postOrder(1, n, 1, n);
for (int i = arr.size() - 1; i >= 0; i--) cout << arr[i] << " ";
cout << endl;
return 0;
}