-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUndiGraph.java
More file actions
33 lines (31 loc) · 915 Bytes
/
UndiGraph.java
File metadata and controls
33 lines (31 loc) · 915 Bytes
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
import java.util.Scanner;
public class UndiGraph {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int [][]mat = new int[n][n];
int [][]adj = new int[n][n];
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
mat[i][j] = sc.nextInt();
}
}
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
if(mat[i][j] != 0){
adj[i][j] = 1;
adj[j][i] = 1;
}else{
adj[i][j] = 0;
adj[j][i] = 0;
}
}
}
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
System.out.print(adj[i][j] + " ");
}
System.out.println();
}
}
}