-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWarshall's algorithm
47 lines (41 loc) · 951 Bytes
/
Warshall's algorithm
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
#include <stdio.h>
void warshall(int arr[10][10],int n){
for(int k=0;k<n;k++){
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
arr[i][j]=arr[i][j] | (arr[i][k] & arr[k][j]);
}
}
}
}
void main(){
int n,flag=0;
int arr[10][10];
printf("Enter number of vertices\n");
scanf("%d",&n);
printf("Enter the adjacency matrix\n");
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
scanf("%d",&arr[i][j]);
}
}
warshall(arr,n);
printf("Transitive Closure: \n");
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
printf("%d ",arr[i][j]);
}
printf("\n");
}
// Modification
for(int i=0;i<n;i++){
if(arr[i][i]==1){
printf("Cycle detected\n");
flag=1;
break;
}
}
if(flag==0){
printf("No cycle detected\n");
}
}