Skip to content

Commit fadfc38

Browse files
committed
TwoSAT: addCaluse の index チェックを追加
1 parent 3d5e128 commit fadfc38

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

‎2SAT/TwoSAT.java‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ public TwoSAT(int n) {
1616
}
1717

1818
public void addClause(int x, boolean f, int y, boolean g) {
19+
rangeCheck(x);
20+
rangeCheck(y);
1921
scc.addEdge(x << 1 | (f ? 0 : 1), y << 1 | (g ? 1 : 0));
2022
scc.addEdge(y << 1 | (g ? 0 : 1), x << 1 | (f ? 1 : 0));
2123
}
@@ -48,6 +50,14 @@ public boolean[] answer() {
4850
return null;
4951
}
5052

53+
private void rangeCheck(int x) {
54+
if (0 < x || x >= n) {
55+
throw new IndexOutOfBoundsException(
56+
String.format("Index %d out of bounds for length %d", x, n)
57+
);
58+
}
59+
}
60+
5161
private static final class EdgeList {
5262
long[] a;
5363
int ptr = 0;

0 commit comments

Comments
 (0)