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