# Tree - Reconstruction of a Tree

Ԑ : 1 sec, : 131072 KB
pł͂

# Reconstruction of a Tree

񕪖؂ɑ΂āAꂼs (preorder tree walk) ƒԏ (inorder tree walk) sēߓ_̗񂪗^̂ŁA̓񕪖؂̌s (postorder tree walk) œߓ_̗o͂vO쐬ĂB

Psڂɓ񕪖؂̐ߓ_̐ $n$ ^܂B
Qsڂɐsœߓ_̔ԍ̗񂪋󔒋؂ŗ^܂B
Rsڂɒԏœߓ_̔ԍ̗񂪋󔒋؂ŗ^܂B

ߓ_ɂ $1$ $n$ ܂ł̐蓖ĂĂ܂B$1$ Ƃ͌ȂƂɒӂĂB

## o

sœߓ_̔ԍ̗Psɏo͂ĂBߓ_̔ԍ̊ԂɂP̋󔒂ĂB

• $1 \leq n \leq 40$

## ͗ 1

5
1 2 3 4 5
3 2 4 1 5


## o͗ 1

3 4 2 5 1


## ͗ 2

4
1 2 3 4
1 2 3 4


## o͗ 2

4 3 2 1