Suppose we have a set of binary trees with their inorder and preorder traversals given, and where no tree is a subtree of another tree in the given set. Now another binary tree $Q$ is given. Find whether it can be formed by joining the binary trees from the given set. (While joining, each tree in the set should be considered atmost once.) Joining operation means: Pick the root of any tree in the set and hook it to any vertex of another tree such that the resulting tree is also a binary tree.
Can we do this using LCA (least common ancestor) or does it needs any special data structure to solve?