Language: C++

#include <iostream>
#include <string>
#include <map>
#include <cctype>
#include <vector>

using namespace std;

#define DEBUG(x) cerr << #x << " = " << x << endl
#define CALL(f) // cerr << f << ": *it = " << *it << endl
#define REP(i,n) for(int i = 0; i < (int)n; ++i)
#define FOR(it,c) for(__typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it)

typedef string::const_iterator iter;

// contains raw id
map<string, int> vars;

struct restype {
    int left_id, is_or, right_id;
    restype(int l, int o, int r) : left_id(l), is_or(o), right_id(r) { }
};

restype expr(iter&it);
restype term(iter& it);
restype factor(iter& it);
restype elem(iter& it);

restype expr(iter& it) {
    CALL("expr");
    restype r = term(it);
    if(*it == '|' || *it == '&') {
        r.is_or = (*it == '|');
        ++it;
        r.right_id = term(it).left_id;
    }
    return r;
}

restype term(iter& it) {
    CALL("term");
    if(*it == '~') {
        ++it;
        restype r = term(it);
        r.left_id ^= 1;
        r.is_or ^= 1;
        r.right_id ^= 1;
        return r;
    }
    else {
        return factor(it);
    }
}

restype factor(iter& it) {
    CALL("factor");
    if(*it == '(') {
        ++it;
        restype r = expr(it);
        ++it;
        return r;
    }
    else {
        return elem(it);
    }
}

// return variable id
restype elem(iter& it) {
    CALL("elem");
    string s;
    while(isalpha(*it)) {
        s.push_back(*it);
        ++it;
    }

    int id;
    if(vars.count(s)) {
        id = vars[s];
    }
    else {
        vars[s] = vars.size();
        id = vars[s];
    }
    return restype(2*id, 1, 2*id);
}

struct Graph {
    int V;
    vector<vector<int> > G, revG;
    vector<int> cmp; // トポロジカル順序

    vector<int> vs; // 帰りがけ順序
    vector<char> used;

    Graph(int v) : V(v), G(v), revG(v), cmp(v), used(v) { }

    void add_edge(int from, int to) {
        G[from].push_back(to);
        revG[to].push_back(from);
    }

    void dfs(int v) {
        used[v] = true;
        FOR(it, G[v]) {
            int to = *it;
            if(used[to] == false) dfs(to);
        }
        vs.push_back(v);
    }

    void rdfs(int v, int k) {
        used[v] = true;
        cmp[v] = k;
        FOR(it, revG[v]) {
            int to = *it;
            if(used[to] == false) rdfs(to, k);
        }
    }

    // @return 強連結成分を潰してDAGを作ったときの頂点数
    int scc() {
        vs.clear();
        fill(used.begin(), used.end(), false);
        REP(v, V) if(used[v] == false) dfs(v);

        int k = 0;
        reverse(vs.begin(), vs.end());
        fill(used.begin(), used.end(), false);

        FOR(it, vs) if(used[*it] == false) rdfs(*it, k++);
        return k;
    }
};

int main() {
    int N, M; cin >> N >> M;
    Graph graph(2*M);
    for(int i = 0; i < N; i++) {
        string s; cin >> s;
        iter it = s.begin();
        restype r = expr(it);
        if(r.is_or) {
            graph.add_edge(r.left_id ^ 1, r.right_id);
            graph.add_edge(r.right_id ^ 1, r.left_id);
        }
        else {
            graph.add_edge(r.left_id ^ 1, r.right_id);
            graph.add_edge(r.right_id ^ 1, r.left_id);
        }
    }
    graph.scc();
    bool f = true;
    for(int i = 0; i < M; i++) {
        if(graph.cmp[2*i] == graph.cmp[2*i+1]) {
            f = false;
            break;
        }
    }
    cout << (f ? "accept" : "reject") << endl;
}

Compiler output:
a.cc: In member function 'int Graph::scc()':
a.cc:128:9: error: 'reverse' was not declared in this scope
  128 |         reverse(vs.begin(), vs.end());
      |         ^~~~~~~