TREEORD  Tree _order
Description
A tree is a connected acyclic graph.
A binary tree is a tree for which each node has a left child, a right child, both, or neither, e.g.
1 / \ 2 3 / \ \ 4 5 6
There are three common ways to recursively traverse such a tree.
 Preorder: parent, left subtree, right subtree
 Postorder: left subtree, right subtree, parent
 Inorder: left subtree, parent, right subtree
Given preorder, postorder, and inorder traversals, determine if they can be of the same binary tree.
For example,
1 2 4 5 3 6 4 5 2 6 3 1 4 2 5 1 3 6are the preorder, postorder, and inorder traversals of the tree above.
But
1 2 4 5 3 6 4 5 2 6 1 3 4 2 5 1 6 3cannot be the preorder, postorder, and inorder tranversals of the same binary tree.
Input
The first line is the number of nodes in each traversal, 0 < N <= 8000.
The second line is the N space seperated nodes of the preorder traveral.
The third line is the N space separated nodes of the postorder traversal.
The fourth line is the N space separated nodes of the inorder traversal.
The second line is the N space seperated nodes of the preorder traveral.
The third line is the N space separated nodes of the postorder traversal.
The fourth line is the N space separated nodes of the inorder traversal.
Each traversal is a sequence of the nodes, numbered 1 to N, without repitition.
Output
Print "yes" if all three traversals can be of the same tree, and "no" otherwise.
Input  Input 

6 1 2 4 5 3 6 4 5 2 6 3 1 4 2 5 1 3 6 
6 1 2 4 5 3 6 4 5 2 6 1 3 4 2 5 1 6 3 
Output  Output 
yes 
no 
hide comments
Archit Jain:
20150101 20:15:22
simple recursion 

Ashish Tilokani:
20140823 14:52:12
no need of tree construction! 

innovolt:
20140320 11:03:03
straightforward........just for practice 

Sonu Bansal:
20140317 06:29:49
nice Problem !!!


Bhavik:
20140308 16:05:34
nice one:) 
Added by:  BYU Admin 
Date:  20140223 
Time limit:  0.5s3s 
Source limit:  50000B 
Memory limit:  1536MB 
Cluster:  Cube (Intel G860) 
Languages:  All except: ASM64 