Skip to content

Instantly share code, notes, and snippets.

@lsiddiqsunny
Last active October 18, 2017 12:05
Show Gist options
  • Save lsiddiqsunny/a2217b2d3878fbb9b090af31ca17f537 to your computer and use it in GitHub Desktop.
Save lsiddiqsunny/a2217b2d3878fbb9b090af31ca17f537 to your computer and use it in GitHub Desktop.
#include<bits/stdc++.h>
using namespace std;
#define mx 505
long long matrix[mx][mx];
int main()
{
memset(matrix,INT_MAX,sizeof matrix);
int n;
scanf("%d",&n);
for(int i=1; i<=n; i++)
{
for(int j=1; j<=n; j++)
{
scanf("%d",&matrix[i][j]);
}
}
for(int k=1; k<=n; k++)
{
for(int i=1; i<=n; i++)
{
for(int j=1; j<=n; j++)
{
if ((matrix[i][k] + matrix[k][j] )< matrix[i][j])
{
matrix[i][j] = matrix[i][k] + matrix[k][j];
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment