Pagini recente » tema | Rating banu tasia (banutasia) | Cod sursa (job #2342286) | Clasament rommmmm | Cod sursa (job #672410)
Cod sursa(job #672410)
using namespace std;
#include <set>
#include <map>
#include <list>
#include <deque>
#include <stack>
#include <queue>
#include <cmath>
#include <ctime>
#include <cctype>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <utility>
#include <iomanip>
#include <fstream>
#include <cstring>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
#define oo (1<<30)
#define f first
#define s second
#define II inline
#define db double
#define ll long long
#define pb push_back
#define mp make_pair
#define Size(V) ((ll)(V.size()))
#define all(V) (V).begin() , (V).end()
#define CC(V) memset((V),0,sizeof((V)))
#define CP(A,B) memcpy((A),(B),sizeof((B)))
#define FOR(i,a,b) for(ll (i)=(a);(i)<=(b);++(i))
#define REP(i, N) for (ll (i)=0;(i)<(ll)(N);++(i))
#define FORit(it, x) for (__typeof((x).begin()) it = (x).begin(); it != (x).end(); ++it)
#define printll(x) printf("%lld",(x))
#define printsp() printf(" ")
#define newline() printf("\n")
#define readll(x) scanf("%lld",&(x))
#define debugll(x) fprintf(stderr,"%lld\n",(x))
#define IN "royfloyd.in"
#define OUT "royfloyd.out"
int** graph;
int size;
bool isPath (int i , int j)
{
return graph[i][j] != 0;
}
void printGraph()
{
for (int i = 0; i < size; i++)
{
for (int j = 0; j < size; j++)
{
cout << graph[i][j] << " ";
}
cout << endl;
}
}
void solve(int test) {
int nodes;
cin >> nodes;
size = nodes;
graph = new int*[nodes];
for (int i = 0; i < nodes; i++)
{
graph[i] = new int[nodes];
for (int j = 0; j < nodes; j++)
{
cin >> graph[i][j];
}
}
// printGraph();
for (int k = 0; k < size; k++)
{
for (int i = 0; i < size; i++)
{
for (int j = 0; j < size; j++)
{
if (isPath(i, k) && isPath(k, j))
{
graph[i][j] = min(graph[i][j], graph[i][k] + graph[k][j]);
}
}
}
}
printGraph();
}
int main() {
#ifndef ONLINE_JUDGE
freopen(IN,"r",stdin);
freopen(OUT,"w",stdout);
#endif
solve(0);
return 0;
}