-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathWeakVertices.java
More file actions
37 lines (32 loc) · 1.42 KB
/
Copy pathWeakVertices.java
File metadata and controls
37 lines (32 loc) · 1.42 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
//Name: Nguyen Minh Hieu
//Matric number: A0200814W
import java.util.*;
import java.io.*;
public class WeakVertices {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
PrintWriter pw = new PrintWriter(System.out);
Integer vertices = Integer.parseInt(br.readLine());
while (vertices != -1) {
Integer [][] adjMatrix = new Integer[vertices][vertices];
for (int i = 0; i < vertices; i ++) {
String[] input = br.readLine().split(" ");
for (int j = 0; j < vertices; j ++) {
adjMatrix[i][j] = Integer.parseInt(input[j]);
}
}
for (int i = 0; i < vertices; i++) {
boolean weak = true;
for (int j = 0; j < vertices; j++) {
for (int k = 0; k < vertices; k ++) {
if (adjMatrix[i][k]==1 && adjMatrix[i][j]==1 && adjMatrix[j][k]==1 && i!=k && i!=j && j!=k) weak = false;
}
}
if (weak) pw.print(i + " ");
}
pw.println();
vertices = Integer.parseInt(br.readLine());
}
pw.flush();
}
}