directed graph implementation to solve train route puzzle