-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWarshall.java
More file actions
54 lines (45 loc) · 1.25 KB
/
Copy pathWarshall.java
File metadata and controls
54 lines (45 loc) · 1.25 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
package warshall;
import java.util.Scanner;
public class Warshall {
public static void main(String[] args) {
Scanner scan=new Scanner(System.in);
int n;
System.out.println("Enter the number of vertices");
n=scan.nextInt();
int adj[][]=new int[n][n];
System.out.println("Enter the adjascency matrix");
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
adj[i][j]=scan.nextInt();
}
}
System.out.println("Entered adjascency matrix");
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
System.out.print(adj[i][j]+" ");
}System.out.println();
}
for(int k=0;k<n;k++)
{
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
adj[i][j]= adj[i][j] | (adj[k][j] & adj[i][k]);
}
}
}
System.out.println("The final matrix is");
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
System.out.print(adj[i][j]+" ");
}System.out.println();
}
}
}