Implemented dictionary for closed.

Changed closed to be a dictionary and print_parents. Successfully
decreased time taken to run program and fixed it so that it works for
all test cases.