Cod sursa(job #3233642)

Utilizator betybety bety bety Data 4 iunie 2024 11:30:07
Problema Floyd-Warshall/Roy-Floyd Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.65 kb
#include <bits/stdc++.h>
using namespace std;
ifstream in("royfloyd.in");
ofstream out("royfloyd.out");
const int inf = 1e8+7;
int dist[105][105];
int n;
int main() {
	in>>n;
	for(int i=1;i<=n;++i) {
		for(int j=1;j<=n;++j) {
			in>>dist[i][j];
			if(i!=j and dist[i][j] == 0) {
				dist[i][j] = inf;
			}
		}
	}
	for(int k=1;k<=n;++k) {
		for(int i=1;i<=n;++i) {
			for(int j=1;j<=n;++j) {
				dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
			}
		}
	}
	for(int i=1;i<=n;++i) {
		for(int j=1;j<=n;++j) {
			if(dist[i][j] >= inf) {
				out<<0<<' ';
			} else {
				out<<dist[i][j]<<' ';
			}
		}
		out<<'\n';
	}
	return 0;
}