Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- using namespace std;
- int n, cost[101][101];
- void citire()
- {
- ifstream f("grafFW.in");
- int i, j;
- f>>n;
- for(i=1;i<=n;i++)
- for(j=1;j<=n;j++)
- f>>cost[i][j];
- }
- int main()
- {
- citire();
- int i, j, k;
- for(k=1;k<=n;k++)
- for(i=1;i<=n;i++)
- for(j=1;j<=n;j++)
- if(i!=j && i!=k && k!=j && cost[i][k]!=-1 && cost[k][j]!=-1 && (cost[i][j]>cost[i][k]+cost[k][j] || cost[i][k]==-1))
- cost[i][j]=cost[i][k]+cost[k][j];
- for(i=1;i<=n;i++)
- {
- for(j=1;j<=n;j++)
- cout<<cost[i][j]<<" ";
- cout<<endl;
- }
- }
- /*
- 5
- -1 -1 -1 -1 10
- -1 -1 -1 10 -1
- -1 -1 -1 -1 10
- 10 10 -1 -1 10
- 50 -1 10 10 -1
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement