Cod sursa(job #961688)

Utilizator Kira96Denis Mita Kira96 Data 12 iunie 2013 18:43:11
Problema Floyd-Warshall/Roy-Floyd Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.51 kb
#include<fstream>
using namespace std;
ifstream f("royfloyd.in");
ofstream g("royfloyd.out");
int mi(int a,int b){if(a<b)return a;return b;};
int d[101][101],i,j,n,k;
int main ()
{
	f>>n;
	for(i=1;i<=n;++i)
		for(j=1;j<=n;++j)
			f>>d[i][j];
	for(k=1;k<=n;++k)
		for(i=1;i<=n;++i)
			for(j=1;j<=n;++j)
			{
				if(d[i][k]&&d[k][j]&&((!d[i][j]&&i!=j)||d[i][k]+d[k][j]<d[i][j]))
				d[i][j]=d[i][k]+d[k][j];
			}
	for(i=1;i<=n;++i)
	{
		for(j=1;j<=n;++j)
			g<<d[i][j]<<" ";
		g<<"\n";
	}
	return 0;
}