Function layeringLongestPath