a variation of 1437D
How to solve 1437D - Minimal Height Tree if the question asked to count the number of valid trees?