Code Library Of Others/sgtlaugh/2SAT.cpp
bool satisfy(vector <int>& res){
        build();
        clr(visited);

        for (int i = 1; i <= m; i++){
            int x = order[i];
            if (parent[x] == parent[neg(x)]) return false;

            if (!visited[parent[x]]){
                visited[parent[x]] = true;
                visited[parent[neg(x)]] = false;
            }
        }

        res.clear();
        for (int i = 1; i <= n; i++){
            if (visited[parent[i]]) res.push_back(i);
        }
        return true;
    }
/// Returns true if the system is 2-satisfiable and returns the solution (nodes set to true) in vector res
Returns true if the system is 2-satisfiable and returns the solution (nodes set to true) in vector res
Returns true if the system is 2 - satisfiable and returns the solution ( nodes set to true ) in vector res
bool satisfy(vector <int>& res){
        build();
        clr(visited);
        for (int i = 1; i <= m; i++){
            int x = order[i];
            if (parent[x] == parent[neg(x)]) return false;
            if (!visited[parent[x]]){
                visited[parent[x]] = true;
                visited[parent[neg(x)]] = false;
            }
        }
        res.clear();
        for (int i = 1; i <= n; i++){
            if (visited[parent[i]]) res.push_back(i);
        }
        return true;
    }
bool satisfy ( vector < int > & res ) { build ( ) ; clr ( visited ) ; for ( int i = 1 ; i <= m ; i ++ ) { int x = order [ i ] ; if ( parent [ x ] == parent [ neg ( x ) ] ) return false ; if ( ! visited [ parent [ x ] ] ) { visited [ parent [ x ] ] = true ; visited [ parent [ neg ( x ) ] ] = false ; } } res . clear ( ) ; for ( int i = 1 ; i <= n ; i ++ ) { if ( visited [ parent [ i ] ] ) res . push_back ( i ) ; } return true ; }
Returns true if the system is 2-satisfiable and returns the solution (nodes set to true) in vector res
Returns true if the system is 2 - satisfiable and returns the solution ( nodes set to true ) in vector res