VictorXjoeY / Notebook

Notebook used for competitive programming!
11 stars 2 forks source link

Implement 2-SAT #13

Closed VictorXjoeY closed 4 years ago

VictorXjoeY commented 4 years ago

Still have to figure out a nice and generic enough way of receiving the boolean formula in the input. Probably should do it as a vector of pairs (a, b) which denote each term in the formula "(a or b)". Negative values would denote the negation of a variable in the terms, i.e. the pair (-a, b) would denote (!a or b). Function would return true or false if the assignment was possible and a global array with ans[a] = true meaning that "a" is true in the solution. Other than that 2-SAT is quite simple, it basically only uses Kosaraju's Algorithm: https://cp-algorithms.com/graph/2SAT.html