fixing bellman ford algorithm for reconstruction