-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path12b.c
51 lines (46 loc) · 826 Bytes
/
12b.c
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
#include<stdio.h>
#include<stdio.h>
int n,opc=0;
int min(int a,int b)
{
return a < b ? a : b;
}
void cpy(int s[n+1][n+1],int d[n+1][n+1])
{
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
d[i][j]=s[i][j];
}
void floyd(int a[n+1][n+1])
{
int r0[n+1][n+1],r1[n+1][n+1];
cpy(a,r0);
for(int k=1;k<=n;k++)
{
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
{
opc++;
r1[i][j]=min(r0[i][j],r0[i][k]+r0[k][j]);
}
cpy(r1,r0);
}
printf("The all pair shortest distance matrix is :\n");
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
printf("%d ",r1[i][j]);
printf("\n");
}
}
void main()
{
printf("Enter the number of vertices : ");
scanf("%d",&n);
int a[n+1][n+1];
printf("Enter the weight matrix : \n");
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
scanf("%d",&a[i][j]);
floyd(a);
}