Cod sursa(job #2665780)

Utilizator Xutzu358Ignat Alex Xutzu358 Data 31 octombrie 2020 12:13:18
Problema Floyd-Warshall/Roy-Floyd Scor 90
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.87 kb
#include <bits/stdc++.h>

using namespace std;

ifstream f("royfloyd.in");
ofstream g("royfloyd.out");

int n;
int mat[105][105];
int oo=2000000009;

int main()
{
    f >> n;
    for (int i=1;i<=n;i++) {
        for (int j=1;j<=n;j++) {
            f >> mat[i][j];
            if (mat[i][j]==0) {
                mat[i][j]=oo;
            }
        }
    }
    for (int k=1;k<=n;k++) {
		for (int i=1;i<=n;i++) {
			for (int j=1;j<=n;j++) {
                if (mat[i][j] > mat[i][k] + mat[k][j] && i!=j && i!=k && k!=j) {
                    mat[i][j] = mat[i][k] + mat[k][j];
                }
			}
		}
    }
    for (int i=1;i<=n;i++) {
		for (int j=1;j<=n;j++) {
            if (mat[i][j]==oo) {
                g << 0 << " ";
            }
            else {
                g<<mat[i][j]<<" ";
            }
		}
		g<<'\n';
	}
    return 0;
}