-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLAB8-warshall.C
54 lines (49 loc) · 873 Bytes
/
LAB8-warshall.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
52
53
54
#include<stdio.h>
#include<conio.h>
void warshall();
int n,adj[10][10],path[10][10];
void main()
{
int i,j,k;
clrscr();
printf("Enter no. of nodes of the graph:");
scanf("%d",&n);
printf("Enter the Adjacency matrix for the graph:\n");
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
scanf("%d",&adj[i][j]);
printf("\n The Adjacency matrix is:\n");
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
printf("%5d",adj[i][j]);
path[i][j]=adj[i][j];
}
printf("\n");
}
warshall();
getch();
}
//CALCULATE THE DIRECT AND INDIRECT EDGES USING INTERMEDIATE VERTICES
void warshall()
{
int i,j,k;
for(k=1;k<=n;k++)
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
path[i][j]=path[i][j] || (path[i][k] && path[k][j]);
printf("\n The Transitive closure is: \n");
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
printf("%5d",path[i][j]);
printf("\n");
}
}
Input:
4
0 1 0 0
0 0 0 1
0 0 0 0
1 0 1 0