Language: C++

#include <iostream>
#include <string>
#include <vector>
#include <set>
#define N 601

using namespace std;

int groups[N]; // roots are group of each person

int solutions = 0;

bool negative_matrix[N][N];

vector<int> solved_vec;

enum Assignment { UNASSIGNED, DIVINE, DEVILISH, CONFLICT };

struct node {
  int index;
  int n_people;
  vector<int> negatives;
  Assignment assignment;
};

node nodes[N];

int root(int x) { //returns the root (group) of the given person
  if (x == groups[x]) {
    return x;
  } else {
    return root(groups[x]);
  }
}

bool same(int x, int y) {
  return (root(x) == root(y));
}

void unite(int x, int y) {
  groups[root(x)] = root(y);
}

void goal_test(vector<node> *nodes_ptr, int p1, int p2) {
  int divine_count = 0;
  int devilish_count = 0;
  for (vector<node>::iterator it = nodes_ptr->begin(); it!= nodes_ptr->end(); it++) {
    if (it->assignment == DIVINE) {
      divine_count += it->n_people;
    } else if (it->assignment == DEVILISH ) {
      devilish_count += it->n_people;
    } else {
      return;
    }
  }
  //cout << "divine count, devilish count: "<< divine_count << " " << devilish_count << endl;
  //cout << " p1 p2 " << p1 << " " << p2 << endl;
  //cout << "solutions: " << solutions << endl;
  if (divine_count == p1 && devilish_count == p2) {
    solutions++;
    if (solutions == 1) {
      for (vector<node>::iterator sol = nodes_ptr->begin(); sol != nodes_ptr->end(); sol++) {
	if (sol->assignment == DIVINE) solved_vec.push_back(sol->index);
      }
    }
  }
}


void propagate(vector<node> *nodes_ptr, int index, bool assignment) {
  vector<node>::iterator cur = nodes_ptr->begin();
  while (cur->index != index) cur++;
  if (cur->assignment == CONFLICT) return; //failed
  if (assignment) {
    if (cur->assignment == DEVILISH) {
      cur->assignment = CONFLICT;
      return;
    }
    if (cur->assignment == DIVINE) return;
    cur->assignment = DIVINE;
    for (vector<int>::iterator neg = cur->negatives.begin(); neg != cur->negatives.end(); neg++) {
      propagate(nodes_ptr, *neg, false);
    }
  } else {
    if (cur->assignment == DIVINE) {
      cur->assignment = CONFLICT;
      return;
    }
    if (cur->assignment == DEVILISH) return;
    cur->assignment = DEVILISH;
    for (vector<int>::iterator neg = cur->negatives.begin(); neg != cur->negatives.end(); neg++) {
      propagate(nodes_ptr, *neg, true);
    }
  }
}

void assign(vector<node> nodes_copy, int p1, int p2, bool assignment) {
  vector<node>::iterator cur = nodes_copy.begin();
  while (cur != nodes_copy.end() && cur->assignment != UNASSIGNED) {
    cur++;
  }
  if (cur == nodes_copy.end()) {
    //do nothing;
    return;
  } else if (assignment) {
    cur->assignment = DIVINE;
    for (vector<int>::iterator neg = cur->negatives.begin(); neg != cur->negatives.end(); neg++) {
      propagate(&nodes_copy, *neg, false);
    }
  } else {
    cur->assignment = DEVILISH;
    for (vector<int>::iterator neg = cur->negatives.begin(); neg != cur->negatives.end(); neg++) {
      propagate(&nodes_copy, *neg, true);
    }
  }
  cur = nodes_copy.begin();
  
  while (cur != nodes_copy.end() && cur->assignment != UNASSIGNED) {
    if (cur->assignment == CONFLICT) {
      cout << "conflicted" << endl;
      return;
    }
    cur++;
  }
  if (cur == nodes_copy.end()) {
    goal_test(&nodes_copy, p1, p2);
    return;
  } else {
    assign(nodes_copy, p1, p2, true);
    assign(nodes_copy, p1, p2, false);
  }
}
      
    

int main()
{
  while (true) {
    int n, p1, p2;
    cin >> n >> p1 >> p2;

    if (n == 0 && p1 == 0 and p2 == 0) break;

    solutions = 0;
    solved_vec.clear();

    for (int i = 0; i < N; i++) {
      for (int j = 0; j < N; j++) {
	negative_matrix[i][j] = false;
      }
    }
    
    

    
    //initialize roots
    for (int i = 1; i <= p1+p2; i++) {
      groups[i] = i;
    }

   
    for (int i = 0; i < n; i++) {
      int x, y;
      string answer;
      cin >> x >> y >> answer;
      if (answer == "yes") {
	unite(x, y);
      } else if (answer == "no") {
	negative_matrix[x][y] = true;
	negative_matrix[y][x] = true;
      }
    }

    //special cases
    if (p1 == 0) {
      cout << "end" << endl;
      continue;
    } else if (p2 == 0) {
      for (int i = 1; i <= p1; i++) {
	cout << i << endl;
      }
      cout << "end" << endl;
      continue;
    } else if (n == 0) {
      cout << "no" << endl;
      continue;
    }

    //initialize nodes
    for (int i = 1; i <= p1+p2; i++) {
      nodes[i].index = i;
      nodes[i].n_people = 0;
      nodes[i].assignment = UNASSIGNED;
      nodes[i].negatives.clear();
    }
    for (int i = 1; i <= p1+p2; i++) {
      nodes[root(i)].n_people++;
    }
    for (int i = 1; i <=p1+p2; i++) {
      for (int j = 1; j<=p1+p2; j++) {
	if (negative_matrix[i][j]) {
	  nodes[root(i)].negatives.push_back(root(j));
	  nodes[root(j)].negatives.push_back(root(i));
	}
      }
    }

    
    //backtrack vector
    vector<node> backtrack_vec;
    for (int i = 1; i <= p1+p2; i++) {
      if (nodes[i].n_people > 0) {
	node new_node = nodes[i];
	backtrack_vec.push_back(new_node);
      }
    }

    
    //cout << "assigning" << endl;
    assign(backtrack_vec, p1, p2, true);
    assign(backtrack_vec, p1, p2, false);
    if (solutions == 1) {
      for (int i = 1; i <= p1 + p2; i++) {
	if (find(solved_vec.begin(), solved_vec.end(), root(i)) != solved_vec.end()) {
	  cout << i << endl;
	}
      }
      cout << "end" << endl;
    } else {
      cout << "no" << endl;
    }
    
    
  }  
}

Compiler output:
a.cc: In function 'int main()':
a.cc:224:17: error: no matching function for call to 'find(std::vector<int>::iterator, std::vector<int>::iterator, int)'
  224 |         if (find(solved_vec.begin(), solved_vec.end(), root(i)) != solved_vec.end()) {
      |             ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/bits/locale_facets.h:48,
                 from /usr/include/c++/14/bits/basic_ios.h:37,
                 from /usr/include/c++/14/ios:46,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/streambuf_iterator.h:435:5: note: candidate: 'template<class _CharT2> typename __gnu_cxx::__enable_if<std::__is_char<_CharT2>::__value, std::istreambuf_iterator<_CharT> >::__type std::find(istreambuf_iterator<_CharT>, istreambuf_iterator<_CharT>, const _CharT2&)'
  435 |     find(istreambuf_iterator<_CharT> __first,
      |     ^~~~
/usr/include/c++/14/bits/streambuf_iterator.h:435:5: note:   template argument deduction/substitution failed:
a.cc:224:17: note:   '__gnu_cxx::__normal_iterator<int*, std::vector<int> >' is not derived from 'std::istreambuf_iterator<_CharT>'
  224 |         if (find(solved_vec.begin(), solved_vec.end(), root(i)) != solved_vec.end()) {
      |             ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~