Modified code to find longest path.