Created
July 5, 2019 11:35
-
-
Save surinoel/f64db9b6c83a5f88c8aa41d109baad0b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <vector> | |
| #include <iostream> | |
| using namespace std; | |
| vector<int> inod, postod; | |
| int inod_root[100001]; | |
| void find_preod(int a, int b, int c, int d) { | |
| if (b - a == 0) return; | |
| int root = postod[d - 1]; | |
| int range = inod_root[root]; | |
| cout << root << ' '; | |
| find_preod(a, range, c, c + range - a); | |
| find_preod(range + 1, b, c + range - a, d - 1); | |
| return; | |
| } | |
| int main(void) { | |
| ios_base::sync_with_stdio(false); | |
| cin.tie(nullptr); | |
| int n; | |
| cin >> n; | |
| inod.resize(n), postod.resize(n); | |
| for (int i = 0; i < n; i++) { | |
| cin >> inod[i]; | |
| inod_root[inod[i]] = i; | |
| } | |
| for (int i = 0; i < n; i++) { | |
| cin >> postod[i]; | |
| } | |
| find_preod(0, n, 0, n); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment