Improved implementation of longest path solver