Language: C++

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

#define N 601

using namespace std;

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


int solutions = 0; //number of unique solutions


vector<int> solved_vec; // to store solutions (divine groups)

enum assign { UNASSIGNED, DIVINE, DEVIL };

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


struct liar_link { // links for liar constraint
  int x; 
  int y;
};

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) {
  // to check if 2 person belong to the same group
  return (root(x) == root(y));
}

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



void goal_test(vector<node> *solution_vec) {
  for (vector<node>::iterator it = solution_vec->begin(); it != solution_vec->end(); ++it) {
    
    if (it->assignment == DIVINE) {
      solved_vec.push_back(it->index);
    }
    
}


void backtrack_aux(vector<node> *nodes, int p1, int p2, vector<node> *solution_vec);

void propagate(vector<node> *nodes, bool assign, int index) {
  //propagate constraints
  vector<node>::iterator it = nodes->begin();
  while (it->index != index) ++it; //look for index
  
  if (it->assignment != UNASSIGNED) return; //end of propagation

  if (assign) { //if divine assignment
    it->assignment = DIVINE;
    for (vector<int>::iterator neg = it->negatives.begin(); neg != it->negatives.end(); neg++) {
      propagate(nodes, false, *neg);
    }
  } else { // devil assignment
    it->assignment = DEVIL;
    for (vector<int>::iterator neg = it->negatives.begin(); neg != it->negatives.end(); neg++) {
      propagate(nodes, true, *neg);
    }
  }
}

void backtrack(vector<node> nodes, bool assign, int p1, int p2, vector<node> solution_vec) {
  if (assign) { //if divine assignment
    nodes[0].assignment = DIVINE;
    //propagate constraints
    for (vector<int>::iterator neg = nodes[0].negatives.begin(); neg != nodes[0].negatives.end(); neg++) {
      propagate(&nodes, false, *neg);
    }
  } else { // if devilish assignment
    nodes[0].assignment = DEVIL;
    //propagate constraints
    for (vector<int>::iterator neg = nodes[0].negatives.begin(); neg != nodes[0].negatives.end(); neg++) {
      propagate(&nodes, true, *neg);
    }
  }
  int divine_accum = 0;
  int devil_accum = 0;
  
  vector<node> new_vec;
  for (vector<node>::iterator it = nodes.begin(); it != nodes.end(); ++it) {
    if (it->assignment == UNASSIGNED) {
      new_vec.push_back(*it);
    } else {
      if (it->assignment == DIVINE) divine_accum += it->n_people;
      if (it->assignment == DEVIL) devil_accum += it->n_people;
      solution_vec.push_back(*it);
    }
  }
  
  if ( divine_accum <= p1 && devil_accum <= p2 ) { // if still on path to goal state
    backtrack_aux(&new_vec, p1 - divine_accum, p2 - devil_accum, &solution_vec);
  }
}


void backtrack_aux(vector<node> *nodes, int p1, int p2, vector<node> *solution_vec) {
  if (p1 == 0 && p2 == 0) {
    //do goal test
    solutions++;
    goal_test(solution_vec);
    return;
  }
  
  if ((*nodes)[0].n_people <= p1) {
    backtrack(*nodes, true, p1, p2, *solution_vec);
  }
  if ((*nodes)[0].n_people <= p2) {
    backtrack(*nodes, false, p1, p2, *solution_vec);
  }
}


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

    if (n == 0 && p1 == 0 && p2 == 0) break; // end of inputs

    solutions = 0; //reset solutions
    solved_vec.clear();

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

    node nodes[N]; // too store groups

    vector<liar_link> liar_links; // constraint map

    //read in answer
    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") {
	liar_link new_link = {x, y};
	liar_links.push_back(new_link); // add constraint
      }
    }

    //special cases
    
    if (p1 == 0) { // no divine
      cout << "end" << endl;
    } else if (p2 == 0) { //all divine
      for (int i = 1; i <= p1; i++) {
	cout << i << endl;
      }
      cout << "end" << endl;
    } else if (n == 0) { // no questions, not possible to determine
      cout << "no" << endl;
    } else {
      //cout <<  " liar_links" << endl;
      for (vector<liar_link>::iterator it = liar_links.begin(); it != liar_links.end(); ++it) {
	nodes[groups[it->x]].negatives.push_back(groups[it->y]);
	nodes[groups[it->y]].negatives.push_back(groups[it->x]);
      }
      
      
      //initialize nodes (groups)
      for (int i = 1; i <= p1 + p2; i++) {
	nodes[i].index = i;
	nodes[i].n_people = 0;
	nodes[i].assignment = UNASSIGNED;
      }
      
      //initialize counts for groups
      for (int i = 1; i <= p1 + p2; i++) {
	nodes[root(i)].n_people++;
      }
      
      //backtrack vector
      vector<node> backtrack_vec;
      for (int i = 1; i <= p1 + p2; i++) {
	if (nodes[i].n_people > 0) { // add only nodes with positive count
	  node new_node = nodes[i];
	  backtrack_vec.push_back(new_node);
	}
      }
      

      vector<node> solution_vec;
	
      backtrack_aux(&backtrack_vec, p1, p2, &solution_vec);

      if (solutions == 1) { //if unique solution found
	for (int i = 0; i < N; 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 'void goal_test(std::vector<node>*)':
a.cc:66:61: error: a function-definition is not allowed here before '{' token
   66 | void propagate(vector<node> *nodes, bool assign, int index) {
      |                                                             ^
a.cc:86:92: error: a function-definition is not allowed here before '{' token
   86 | void backtrack(vector<node> nodes, bool assign, int p1, int p2, vector<node> solution_vec) {
      |                                                                                            ^
a.cc:120:85: error: a function-definition is not allowed here before '{' token
  120 | void backtrack_aux(vector<node> *nodes, int p1, int p2, vector<node> *solution_vec) {
      |                                                                                     ^
a.cc:137:9: warning: empty parentheses were disambiguated as a function declaration [-Wvexing-parse]
  137 | int main() {
      |         ^~
a.cc:137:9: note: remove parentheses to default-initialize a variable
  137 | int main() {
      |         ^~
      |         --
a.cc:137:9: note: or replace parentheses with braces to value-initialize a variable
a.cc:137:12: error: a function-definition is not allowed here before '{' token
  137 | int main() {
      |            ^
a.cc:229:2: error: expected '}' at end of input
  229 | }
      |  ^
a.cc:54:44: note: to match this '{'
   54 | void goal_test(vector<node> *solution_vec) {
      |                                            ^