-
Notifications
You must be signed in to change notification settings - Fork 59
/
A.java
48 lines (41 loc) · 1.14 KB
/
A.java
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
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
public class A {
private int[] vertices;
private boolean[][] edges;
private int edgeCount;
public A(File file) throws IOException {
readGraph(file);
}
private void readGraph(File file) throws FileNotFoundException, IOException {
BufferedReader br = new BufferedReader(new FileReader(file));
String line;
while ((line = br.readLine()) != null) {
if (line.startsWith("c")) continue;
String[] split = line.split("\\s+");
if (line.startsWith("p")) {
int vertexCount = Integer.parseInt(split[2]);
int edgeCount = Integer.parseInt(split[3]);
this.vertices = new int[vertexCount];
this.edges = new boolean[vertexCount][vertexCount];
this.edgeCount = edgeCount;
}
else {
int left = Integer.parseInt(split[1]);
int right = Integer.parseInt(split[2]);
this.edges[left][right] = true;
this.edges[right][left] = true;
}
}
br.close();
}
public int[] getVertices() {
return this.vertices;
}
public boolean[][] getEdges() {
return this.edges;
}
}