Solution to longest path in a graph problem.