Last updated 3 years ago
DP based approach Including each intermediate node one by one
void findSortestPath(vector<vector<int>> &v, int n) { for (int k = 0; k < n; k++) { for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { v[i][j] = min(v[i][j], v[i][k] + v[k][j]); } } } }
Time Complexity: O(V^3)