I read from MIT lectures, that algorithm for all pair shortest path is

for m in range(1,n)

for u in V

for v in V

for x in V

if d_{uv}>d_{ux}+d_{xv}

d_{uv}=d_{ux}+d_{xv}

But in all other places algorithm is like

for(int k = 1; k <= n; k++){

for(int i = 1; i <= n; i++){

for(int j = 1; j <= n; j++){

dist[i][j] = min( dist[i][j], dist[i][k] + dist[k][j] );

}

}

}

Plz explain me which one correct and why?