Pagini recente » Cod sursa (job #3360466) | Cod sursa (job #3360441) | Cod sursa (job #3360410) | Cod sursa (job #3360451) | Cod sursa (job #3360424)
#include <bits/stdc++.h>
using namespace std;
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
ifstream fin ("royfloyd.in");
ofstream fout ("royfloyd.out");
const int INF = 1e8;
int adj[110][110];
int main()
{
FASTIO
int n; fin >> n;
for(int i = 1; i <= n; i++)
for(int j = 1; j <= n; j++)
fin >> adj[i][j];
vector<vector<int>> dist(n + 1, vector<int>(n + 1));
for(int i = 1; i <= n; i++)
for(int j = 1; j <= n; j++){
if(i != j && adj[i][j] == 0) dist[i][j] = INF;
else dist[i][j] = adj[i][j];
}
for(int k = 1; k <= n; k++)
for(int i = 1; i <= n; i++)
for(int j = 1; j <= n; j++)
if(dist[i][j] > dist[i][k] + dist[k][j])
dist[i][j] = dist[i][k] + dist[k][j];
for(int i = 1; i <= n; i++){
for(int j = 1; j <= n; j++)
fout << dist[i][j] << ' ';
fout << '\n';
}
return 0;
}