With all terms pre-calculated before each iteration, the time complexity of computingL A is just O(k 2 ).
the total time complexity of computing L A is decreased to O(2|V |k 2 + 2|V |k + k 2 ) ≈ O(2|V |k 2 ), which is much smaller than the original O(k|V | 2 ).