Logo
(追記) (追記ここまで)

7604번 - Reconstruction Trees 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 128 MB127373141.892%

문제

It is very easy to produce the various traversals of a binary tree, however this problem requires you to produce the tree from the traversals. Specifically, given the pre-order and in-order traversals of a binary tree (not necessarily a binary search tree), reconstruct, if possible, the original tree.

For instance, the following tree will produce the traversals shown

 E
 / \
 D F
 / \
 B G
 / \ \
A C I
 / \
 H K
 /
 J
Preorder : EDBACFGIHKJ
Inorder : ABCDEFGHIJK
Postorder: ACBDHJKIGFE 

입력

Input will consist of representations of several trees, each on a single line, and terminated by a #. Each line will consist of two strings of up to 26 unique uppercase letters in the form

<pre-order> <space> <in-order>.

You can assume that the two strings will be permutations of each other.

출력

Output will consist of the post-order traversal of the reconstructed tree if possible, otherwise the words 'Invalid tree'.

제한

예제 입력 1

EDBACFGIHKJ ABCDEFGHIJK
#

예제 출력 1

ACBDHJKIGFE

힌트

출처

ICPC > Regionals > South Pacific > South Pacific Region > New Zealand Programming Contest > NZPC 2008 J번

  • 데이터를 추가한 사람: kajebiii
(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /