Skip to content

Commit 73b73d8

Browse files
committed
TwoSAT#answer の返り値を boolean[] に変更
1 parent 947938b commit 73b73d8

2 files changed

Lines changed: 9 additions & 6 deletions

File tree

‎2SAT/Readme.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public boolean satisfiable()
9090
### answer
9191

9292
```java
93-
public java.util.BitSet answer()
93+
public boolean[] answer()
9494
```
9595

9696
`satisfiable` を最後に呼んだ時点での、クローズを満たす割当を返す。割当が存在しなかった場合は `null` を返す。
@@ -107,4 +107,4 @@ $O(n)$
107107

108108
## 使用例
109109

110-
[AtCoder Library Practice Contest H - Two SAT](https://atcoder.jp/contests/practice2/submissions/16603939)
110+
[AtCoder Library Practice Contest H - Two SAT](https://atcoder.jp/contests/practice2/submissions/16647102)

‎2SAT/TwoSAT.java‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
1+
/**
2+
* @verified https://atcoder.jp/contests/practice2/submissions/16647102
3+
*/
14
class TwoSAT {
25
private final int n;
36
private final InternalSCC scc;
4-
private final java.util.BitSet answer;
7+
private final boolean[] answer;
58

69
private boolean hasCalledSatisfiable = false;
710
private boolean existsAnswer = false;
811

912
public TwoSAT(int n) {
1013
this.n = n;
1114
this.scc = new InternalSCC(2 * n);
12-
this.answer = new java.util.BitSet(n);
15+
this.answer = new boolean[n];
1316
}
1417

1518
public void addClause(int x, boolean f, int y, boolean g) {
@@ -30,12 +33,12 @@ public boolean satisfiable() {
3033
int[] ids = scc.ids();
3134
for (int i = 0; i < n; i++) {
3235
if (ids[i << 1 | 0] == ids[i << 1 | 1]) return existsAnswer = false;
33-
answer.set(i, ids[i << 1 | 0] < ids[i << 1 | 1]);
36+
answer[i] = ids[i << 1 | 0] < ids[i << 1 | 1];
3437
}
3538
return existsAnswer = true;
3639
}
3740

38-
public java.util.BitSet answer() {
41+
public boolean[] answer() {
3942
if (!hasCalledSatisfiable) {
4043
throw new UnsupportedOperationException(
4144
"Call TwoSAT#satisfiable at least once before TwoSAT#answer."

0 commit comments

Comments
 (0)