If we igone the -1 and created a directed graph with 1 as a root. We just need to check is there any cycle ion the graph or not. If we found cycle then the answer is "Not Valid" otherwise "Valid"