Problem 2674 --Tree - Reconstruction of a Tree

2674: Tree - Reconstruction of a Tree

"
Time Limit $1$ 秒/Second(s) Memory Limit $512$ 兆字节/Megabyte(s)
提交总数 $5$ 正确数量 $4$
裁判形式 标准裁判/Standard Judge 我的状态 尚未尝试
难度 分类标签

Reconstruction of a Tree

Write a program which reads two sequences of nodes obtained by the preorder tree walk and the inorder tree walk on a binary tree respectively, and prints a sequence of the nodes obtained by the postorder tree walk on the binary tree.

In the first line, an integer n, which is the number of nodes in the binary tree, is given. 

In the second line, the sequence of node IDs obtained by the preorder tree walk is given separated by space characters. In the second line, the sequence of node IDs obtained by the inorder tree walk is given separated by space characters.

Every node has a unique ID from 1 to n. Note that the root does not always correspond to 1.

Print the sequence of node IDs obtained by the postorder tree walk in a line. Put a single space character between adjacent IDs.
5
1 2 3 4 5
3 2 4 1 5
3 4 2 5 1
1≤ n≤ 40

推荐代码 查看2674 所有题解 上传题解视频得图灵币

本题记录 用 户(点击查看用户) 运行号(点击购买题解) 时 间
算法最快[$0 $ms] 计爱玲 362682 2019-01-30 17:24:52
内存最少[$2020 $KB] 计爱玲 362682 2019-01-30 17:24:52
第一AC 计爱玲 362682 2019-01-30 17:24:52
第一挑战 计爱玲 362681 2019-01-30 17:08:21

赛题来源/所属竞赛 会津大学《挑战数据结构与算法》 挑战数据结构与算法

竞赛编号 竞赛名称 竞赛时间 访问比赛