Skip to content

Instantly share code, notes, and snippets.

@shubham100795
Created April 20, 2017 13:40
Show Gist options
  • Save shubham100795/5161b2a013863a6b0d1dea97d7b4e558 to your computer and use it in GitHub Desktop.
Save shubham100795/5161b2a013863a6b0d1dea97d7b4e558 to your computer and use it in GitHub Desktop.
Warshall's algorithm to find the path matrix
#include<iostream>
using namespace std;
int main()
{
int ar[4][4]={{0,1,0,1},{1,0,1,1},{0,0,0,1},{1,0,1,0}};
for(int k=0;k<4;k++)
{
for(int i=0;i<4;i++)
{
for(int j=0;j<4;j++)
{
ar[i][j]=(ar[i][j]||(ar[i][k]&&ar[k][j]));
}
}
cout<<"P"<<k<<" is"<<endl;
for(int i=0;i<4;i++)
{
for(int j=0;j<4;j++)
{
cout<<ar[i][j]<<" ";
}
cout<<endl;
}
cout<<endl;
}
cout<<"P3 is the path matrix"<<endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment