Language: C++

#include <bits/stdc++.h>
using namespace std;

using pii = pair<int, int>;

struct edge {
    int to;
    bool yes;
};

using edges = vector<edge>;
using graph = vector<edges>;

// (divine, devilish)
pii dfs(graph const& g, int v, bool divine, vector<bool>& checked) {
    auto res = make_pair((int)divine, (int)!divine);
    checked[v] = true;
    for(auto& e : g[v]) {
        if(checked[e.to]) {
            continue;
        }
        bool next_state = (divine && e.yes || !divine && !e.yes);
        auto t = dfs(g, e.to, next_state, checked);
        res.first += t.first;
        res.second += t.second;
    }
    return res;
}

void determine(graph const& g, int v, bool divine, vector<int>& res) {
    res[v] = divine;
    for(auto& e : g[v]) {
        if(res[e.to] != -1) {
            continue;
        }
        bool next_state = (divine && e.yes || !divine && !e.yes);
        determine(g, e.to, next_state, res);
    }
}

struct data {
    int person_id;
    bool divine;
    pii each_num; // (divine, devilish)
    data() : person_id(-1), divine(false), each_num(make_pair(0, 0))
    {}
};

int main() {
    int n, p1, p2;
    while(cin >> n >> p1 >> p2, n || p1 || p2) {
        graph g(p1 + p2);
        if(n == 0) {
            if(p2 == 0) {
                for(int i = 1; i <= p1 + p2; ++i) {
                    cout << i << endl;
                }
            } else if(p1 != 0) {
                cout << "no" << endl;
                continue;
            }
            cout << "end" << endl;
            continue;
        }
        for(int i = 0; i < n; ++i) {
            int x, y;
            string a;
            cin >> x >> y >> a;
            g[x - 1].push_back(edge{y - 1, a == "yes"});
            g[y - 1].push_back(edge{x - 1, a == "yes"});
        }
        vector<vector<vector<data>>> dp(1, vector<vector<data>>(p1 + 1, vector<data>(p2 + 1)));
        dp[0][0][0].person_id = 0;
        vector<bool> checked(p1 + p2);
        for(int i = 0; i < p1 + p2; ++i) {
            auto now = dp.back();
            vector<vector<data>> nxt(p1 + 1, vector<data>(p2 + 1));
            if(!checked[i]) {
                for(int b = 0; b <= 1; ++b) {
                    data d;
                    d.person_id = i;
                    d.divine = b;
                    auto checked2 = checked;
                    d.each_num = dfs(g, i, b, checked);
                    if(b == 0) {
                        checked = checked2; // restore
                    }
                    for(int j = 0; j <= p1; ++j) {
                        for(int k = 0; k <= p2; ++k) {
                            if(now[j][k].person_id == -1) {
                                continue;
                            }
                            int nj = j + d.each_num.first, nk = k + d.each_num.second;
                            if(nj > p1 || nk > p2 || nxt[nj][nk].person_id == -2) {
                                continue;
                            }
                            if(nxt[nj][nk].person_id >= 0 || now[j][k].person_id == -2) { // ambiguous
                                nxt[nj][nk].person_id = -2;
                                continue;
                            }
                            nxt[nj][nk] = d;
                        }
                    }
                }
                dp.push_back(move(nxt));
            }
        }
        auto now = dp.back()[p1][p2];
        if(now.person_id < 0) {
            cout << "no" << endl;
        } else {
            vector<int> res(p1 + p2, -1);
            int P1 = p1, P2 = p2;
            for(int i = dp.size() - 1; i > 0; --i) {
                auto d = dp[i][P1][P2];
                determine(g, d.person_id, d.divine, res);
                P1 -= d.each_num.first;
                P2 -= d.each_num.second;
            }
            for(int i = 0; i < p1 + p2; ++i) {
                if(res[i] == 1) {
                    cout << i + 1 << endl;
                }
            }
            cout << "end" << endl;
        }
    }
}


Compiler output:
a.cc: In function 'int main()':
a.cc:72:30: error: template argument 1 is invalid
   72 |         vector<vector<vector<data>>> dp(1, vector<vector<data>>(p1 + 1, vector<data>(p2 + 1)));
      |                              ^~~~
a.cc:72:30: error: template argument 2 is invalid
a.cc:72:34: error: template argument 1 is invalid
   72 |         vector<vector<vector<data>>> dp(1, vector<vector<data>>(p1 + 1, vector<data>(p2 + 1)));
      |                                  ^~
a.cc:72:34: error: template argument 2 is invalid
a.cc:72:36: error: template argument 1 is invalid
   72 |         vector<vector<vector<data>>> dp(1, vector<vector<data>>(p1 + 1, vector<data>(p2 + 1)));
      |                                    ^
a.cc:72:36: error: template argument 2 is invalid
a.cc:72:58: error: template argument 1 is invalid
   72 |         vector<vector<vector<data>>> dp(1, vector<vector<data>>(p1 + 1, vector<data>(p2 + 1)));
      |                                                          ^~~~
a.cc:72:58: error: template argument 2 is invalid
a.cc:72:62: error: template argument 1 is invalid
   72 |         vector<vector<vector<data>>> dp(1, vector<vector<data>>(p1 + 1, vector<data>(p2 + 1)));
      |                                                              ^~
a.cc:72:62: error: template argument 2 is invalid
a.cc:72:84: error: template argument 1 is invalid
   72 |         vector<vector<vector<data>>> dp(1, vector<vector<data>>(p1 + 1, vector<data>(p2 + 1)));
      |                                                                                    ^
a.cc:72:84: error: template argument 2 is invalid
a.cc:72:94: error: expression list treated as compound expression in initializer [-fpermissive]
   72 |         vector<vector<vector<data>>> dp(1, vector<vector<data>>(p1 + 1, vector<data>(p2 + 1)));
      |                                                                                              ^
a.cc:73:11: error: invalid types 'int[int]' for array subscript
   73 |         dp[0][0][0].person_id = 0;
      |           ^
a.cc:76:27: error: request for member 'back' in 'dp', which is of non-class type 'int'
   76 |             auto now = dp.back();
      |                           ^~~~
a.cc:77:27: error: template argument 1 is invalid
   77 |             vector<vector<data>> nxt(p1 + 1, vector<data>(p2 + 1));
      |                           ^~~~
a.cc:77:27: error: template argument 2 is invalid
a.cc:77:31: error: template argument 1 is invalid
   77 |             vector<vector<data>> nxt(p1 + 1, vector<data>(p2 + 1));
      |                               ^~
a.cc:77:31: error: template argument 2 is invalid
a.cc:77:57: error: template argument 1 is invalid
   77 |             vector<vector<data>> nxt(p1 + 1, vector<data>(p2 + 1));
      |                                                         ^
a.cc:77:57: error: template argument 2 is invalid
a.cc:77:66: error: expression list treated as compound expression in initializer [-fpermissive]
   77 |             vector<vector<data>> nxt(p1 + 1, vector<data>(p2 + 1));
      |                                                                  ^
a.cc:80:21: error: reference to 'data' is ambiguous
   80 |                     data d;
      |                     ^~~~
In file included from /usr/include/c++/14/string:53,
                 from /usr/include/c++/14/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:52,
                 from a.cc:1:
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:41:8: note:                 'struct data'
   41 | struct data {
      |        ^~~~
a.cc:81:21: error: 'd' was not declared in this scope
   81 |                     d.person_id = i;
      |                     ^
a.cc:94:43: error: 'nk' was not declared in this scope; did you mean 'nj'?
   94 |                             if(nj > p1 || nk > p2 || nxt[nj][nk].person_id == -2) {
      |                                           ^~
      |                                           nj
a.cc:94:57: error: invalid types 'int[int]' for array subscript
   94 |                             if(nj > p1 || nk > p2 || nxt[nj][nk].person_id == -2) {
      |                                                         ^
a.cc:97:35: error: invalid types 'int[int]' for array subscript
   97 |                             if(nxt[nj][nk].person_id >= 0 || now[j][k].person_id == -2) { // ambiguous
      |                                   ^
a.cc:97:40: error: 'nk' was not declared in this scope; did you mean 'nj'?
   97 |                             if(nxt[nj][nk].person_id >= 0 || now[j][k].person_id == -2) { // ambiguous
      |                                        ^~
      |                                        nj
a.cc:98:36: error: invalid types 'int[int]' for array subscript
   98 |                                 nxt[nj][nk].person_id = -2;
      |                                    ^
a.cc:101:32: error: invalid types 'int[int]' for array subscript
  101 |                             nxt[nj][nk] = d;
      |                                ^
a.cc:101:37: error: 'nk' was not declared in this scope; did you mean 'nj'?
  101 |                             nxt[nj][nk] = d;
      |                                     ^~
      |                                     nj
a.cc:105:20: error: request for member 'push_back' in 'dp', which is of non-class type 'int'
  105 |                 dp.push_back(move(nxt));
      |                    ^~~~~~~~~
a.cc:108:23: error: request for member 'back' in 'dp', which is of non-class type 'int'
  108 |         auto now = dp.back()[p1][p2];
      |                       ^~~~
a.cc:114:28: error: request for member 'size' in 'dp', which is of non-class type 'int'
  114 |             for(int i = dp.size() - 1; i > 0; --i) {
      |                            ^~~~
a.cc:115:28: error: invalid types 'int[int]' for array subscript
  115 |                 auto d = dp[i][P1][P2];
      |                            ^