Cod sursa(job #2726178)

Utilizator WladDalwMvladutu cristian vlad WladDalwM Data 20 martie 2021 14:17:37
Problema Floyd-Warshall/Roy-Floyd Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1 kb
			    #include <bits/stdc++.h>

			      using namespace std;

				     int n;
				int d[105][105];
			      const int inf = 1e9;

				   int main()
				       {
			  ifstream cin("royfloyd.in");
			 ofstream cout("royfloyd.out");
				     int n;
				   cin >> n;
			  for(int i = 1; i <= n; ++i)
				       {
			  for(int j = 1; j <= n; ++j)
				       {
				     int a;
				   cin >> a;
			      if(a == 0 && i != j)
				       {
				 d[i][j] = inf;
				       }
				      else
				       {
				  d[i][j] = a;
				       }
				       }
				       }
			  for(int k = 1; k <= n; ++k)
				       {
			  for(int i = 1; i <= n; ++i)
				       {
			  for(int j = 1; j <= n; ++j)
				       {
			if(d[i][j] > d[i][k] + d[k][j])
				       {
			  d[i][j] = d[i][k] + d[k][j];
				       }
				       }
				       }
				       }
			  for(int i = 1; i <= n; ++i)
				       {
			  for(int j = 1; j <= n; ++j)
				       {
			    cout << d[i][j] << " ";
				       }
				 cout << '\n';
				       }
				   return 0;
				       }