Undirected Graph Tree Validation - Coding problem | OneNoughtOne