-
Notifications
You must be signed in to change notification settings - Fork 47
Expand file tree
/
Copy pathAllPairShortestPath.c
More file actions
66 lines (66 loc) · 1.17 KB
/
AllPairShortestPath.c
File metadata and controls
66 lines (66 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include <stdio.h>
int x [50][50];
int y [50][50];
int apsp(int n)
{
int i,j,k,q;
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
x[i][j]=y[i][j];//coping the matrix
}
}
printf("\n X0 :\t");
for(i=0;i<n;i++)
{
printf(" %d\t",i+1);
}
printf("\n");
for(i=0;i<n;i++)
{
printf(" %d\t",i+1);
for(j=0;j<n;j++)
{
printf(" %d\t",x[i][j]);
}
printf("\n");
}
for(k=0;k<n;k++)
{
printf(" \n X%d : \n",k+1);
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
q=x[i][k]+x[k][j];
if(q<x[i][j])
x[i][j]=q;
}
}
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
printf(" %d\t",x[i][j]);
}
printf("\n");
}
}
return 0;
}
int main()
{
int n,i,j;
printf("\n Enter the number of nodes : ");
scanf("%d",&n);
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
printf("\n y[%d][%d] = ",i,j);
scanf("%d",&y[i][j]);
}
}
return apsp(n);
}