Here is my code to implement Floyd algorithm. How can I change this algorithm to solve this question: Find the minimum distances between vertices i and j with at most S vertices between them.
void Floyd_Warshal(int graph[MAX][MAX], int D[MAX][MAX], int P[MAX][MAX], int numberOfNodes){
for(int i = 0 ; i < numberOfNodes ; i++)
for(int j = 0 ; j < numberOfNodes ; j++){
D[i][j] = graph[i][j];
P[i][j] = -1;
}
for(int k = 0 ; k < numberOfNodes ; k++)
for(int i = 0 ; i < numberOfNodes ; i++)
for(int j = 0 ; j < numberOfNodes ; j++)
if(D[i][j] > D[i][k] + D[k][j]){
D[i][j] = D[i][k] + D[k][j];
P[i][j] = k;
}
}