Cod sursa(job #961683)

Utilizator predatorGigi Valoare predator Data 12 iunie 2013 18:38:29
Problema Floyd-Warshall/Roy-Floyd Scor 10
Compilator cpp Status done
Runda Arhiva educationala Marime 0.47 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][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][0];
	for(k=1;k<=n;++k)
		for(i=1;i<=n;++i)
			for(j=1;j<=n;++j)
				d[i][j][k]=mi(d[i][j][k-1],d[i][k][k-1]+d[k][j][k-1]);
	for(i=1;i<=n;++i)
	{
		for(j=1;j<=n;++j)
			g<<d[i][j][n]<<" ";
		g<<"\n";
	}
	return 0;
}