def test1(self): graph = { 1: [2, 3, 4], 2: [4, 6], 3: [5, 6, 7, 8], 4: [5, 7], 6: [7, 8], 7: [8], 8: [] } sol = Solution() res = sol.shortest_path_no_cycle(graph, 1, 8) print res