-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfloydwarshall.cpp
58 lines (48 loc) · 1.23 KB
/
floydwarshall.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include<bits/stdc++.h>
using namespace std;
int main(){
int n=4, i=0, j=0, k=0;
// cout<<"Enter No of Vertices :: ";
// cin>>n;
double graph[n][n]={
{0, 5, INFINITY, 10},
{INFINITY, 0, 3, INFINITY},
{INFINITY, INFINITY, 0, 1},
{INFINITY, INFINITY, INFINITY, 0}
};
// for(i=0; i<n; i++){
// for(j=0; j<n; j++){
// if(i==j){
// graph[i][j]=0;
// }
// else{
// cout<<"Enter Weight of Edge from "<<i+1<<" to "<<j+1<<" :: ";
// cin>>graph[i][j];
// }
// }
// }
cout<<"\n\nGraph Before Processing"<<endl;
for(i=0; i<n; i++){
for(j=0; j<n; j++){
cout<<graph[i][j]<<"\t";
}
cout<<endl;
}
for(k=0; k<n; k++){
for(i=0; i<n; i++){
for(j=0; j<n; j++){
if(i!=j){
graph[i][j]=min(graph[i][j], graph[i][k]+graph[k][j]);
}
}
}
}
cout<<"\n\nGraph After Processing"<<endl;
for(i=0; i<n; i++){
for(j=0; j<n; j++){
cout<<graph[i][j]<<"\t";
}
cout<<endl;
}
return 0;
}