66struct TwoSAT {
77 std::vector<std::vector<int >> G;
88 std::vector<int > dfn, low, stk, bel, in;
9- TwoSAT (void ) = default ;
9+ // TwoSAT(void) = default;
1010 TwoSAT (int n) : G(2 * n) {}
1111 void tarjan (int u, int &cnt, int &cc) {
1212 dfn[u] = low[u] = ++cnt;
@@ -30,11 +30,32 @@ struct TwoSAT {
3030 }
3131 // Add constraint: x = a or y = b.
3232 inline void add (int x, bool a, int y, bool b) {
33- size_t should = 2 * (std::max (x, y) + 1 );
34- if (G.size () < should) G.resize (should);
33+ // size_t should = 2 * (std::max(x, y) + 1);
34+ // if (G.size() < should) G.resize(should);
3535 G[x << 1 | !a].push_back (y << 1 | b);
3636 G[y << 1 | !b].push_back (x << 1 | a);
3737 }
38+ // Add constraint: x = a => y = b;
39+ inline void conduct (int x, bool a, int y, bool b) {
40+ // size_t should = 2 * (std::max(x, y) + 1);
41+ // if (G.size() < should) G.resize(should);
42+ G[x << 1 | a].push_back (y << 1 | b);
43+ }
44+ inline void same (int x, int y) {
45+ conduct (x, true , y, true );
46+ conduct (y, true , x, true );
47+ conduct (x, false , y, false );
48+ conduct (y, false , x, false );
49+ }
50+ inline void diff (int x, int y) {
51+ conduct (x, true , y, false );
52+ conduct (y, true , x, false );
53+ conduct (x, false , y, true );
54+ conduct (y, false , x, true );
55+ }
56+ inline void set (int x, bool v) {
57+ conduct (x, !v, x, v);
58+ }
3859 inline void init (void ) { // find scc.
3960 int n = G.size (), cnt = 0 , cc = 0 ;
4061 in = dfn = low = bel = std::vector<int >(n, 0 );
0 commit comments