Pagini recente » Cod sursa (job #3359756) | Cod sursa (job #3359704) | Cod sursa (job #3359700) | Cod sursa (job #3359702) | Cod sursa (job #3359696)
#include <iostream>
using namespace std;
int M[105][105];
int A[105][105];
const int INF = 0x3f3f3f3f;
int main(){
freopen("royfloyd.in","r",stdin);
freopen("royfloyd.out","w",stdout);
int V;
cin >> V;
for(int i = 0;i < V; ++i)
for(int j = 0;j < V; ++j)
cin >> M[i][j];
for(int i = 0; i < V; ++i)
for(int j = 0; j < V; ++j)
if(i != j && M[i][j] != 0)
A[i][j] = M[i][j];
else if(i != j)
A[i][j] = INF;
else
A[i][j] = 0;
for(int k = 0;k < V; ++k)
for(int i = 0;i < V; ++i)
for(int j = 0;j < V; ++j)
if(A[i][j] > A[i][k] + A[k][j])
A[i][j] = A[i][k] + A[k][j];
for(int i = 0;i < V; ++i){
for(int j = 0;j < V; ++j)
cout << A[i][j] << " ";
cout << '\n';
}
return 0;
}