티스토리 뷰
백준 소스코드 [C++] 2263 트리의 순회
#include <iostream>
#include <algorithm>
#include <queue>
#include <string.h>
#include <limits.h>
#include <vector>
#include <math.h>
#include <stack>
#include <bitset>
#include <string>
#include <set>
#define all(v) v.begin(), v.end()
#define pii pair<int,int>
#define make_unique(v) v.erase(unique(v.begin(), v.end()), v.end())
typedef long long ll;
using namespace std;
vector<int> idx,post,in;
void preorder(int postL, int postR, int inL, int inR) {
if (postR < postL || inR < inL) return;
cout << post[postR] << " ";
preorder(postL, postL+idx[post[postR]]-inL-1,inL, idx[post[postR]] - 1);
preorder(postL + idx[post[postR]] - inL, postR-1, idx[post[postR]] +1,inR);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
idx.resize(n+1); post.resize(n+1); in.resize(n+1);
for (int i = 1;i <= n;i++) {
cin >> in[i];
idx[in[i]] = i;
}
for (int i = 1;i <= n;i++) cin >> post[i];
preorder(1,n,1,n);
return 0;
}
'백준' 카테고리의 다른 글
백준 소스코드 [C++] 2467 용액 (0) | 2021.03.02 |
---|---|
백준 소스코드 [C++] 12920 평범한 배낭 2 (0) | 2021.03.01 |
백준 소스코드 [C++] 11478 서로 다른 부분 문자열의 개수 (0) | 2021.02.27 |
백준 소스코드 [C++] 13925 수열과 쿼리 13 (0) | 2021.02.25 |
백준 소스코드 [C++] 11438 LCA 2 (0) | 2021.02.24 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
TAG
- WWDC17
- 네트워크 플로우
- 최대 매칭
- 최단경로 문제
- HIG
- test coverage
- mach-o
- 컴퓨터 추상화
- WWDC21
- 에드몬드 카프 알고리즘
- 벨만포드 알고리즘
- IOS
- rxswift
- 최단경로문제
- State Restoration
- Testable
- 네트워크 유량
- CPU와 Memory
- WWDC16
- WWDC19
- 다익스트라 시간복잡도
- 부스트캠프 6기
- 포드 풀커슨 알고리즘
- MeTal
- 강한 순환 참조
- 코딩대회
- observeOn
- 벨만포드 시간복잡도
- CompositionalLayout
- 최단경로 알고리즘
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
글 보관함