Dynamic programming and associated graph algorithms