I am not able to understand the way input is given. Can somebody help me out on how to construct the tree from given input in tree section?
How to take input in the tree problems?
It is specified in the problem itself. I have encountered two types of problems.
-
Given n nodes and parent of n-1 nodes with 1 being the root. In such case, you know the parent of each node along with the root, and you can continue approaching problem with it.
-
Given n nodes and n-1 edges. In such a problem, you can use the graph approach to make the tree, using adjacency list technique.