#include #include #include #include #include #include using namespace std; int main() { int n, p1, p2, x, y, i, j, k; string a; list < pair< set, set > > c; int table[700][700], which[700][700]; ifstream fin("liar.txt"); while (fin >> n >> p1 >> p2) { if (n == 0 && p1 == 0 && p2 == 0) { break; } c.clear(); for (i = 1; i <= p1+p2; i++) { pair< set, set > p = make_pair(set(), set()); p.first.insert(i); c.push_back(p); } for (i = 0; i < n; i++) { fin >> x >> y >> a; if (x == y) { continue; } list< pair< set, set > >::iterator ci = c.end(), cj = c.end(); for (list < pair< set, set > >::iterator p = c.begin(); p != c.end(); p++) { if (p->first.find(x) != p->first.end()) { ci = p; } if (p->second.find(x) != p->second.end()) { ci = p; swap(p->first, p->second); } if (p->first.find(y) != p->first.end()) { cj = p; } if (p->second.find(y) != p->second.end()) { cj = p; swap(p->first, p->second); } } if (ci == cj) { continue; } if (a == "no") { swap(cj->first, cj->second); } ci->first.insert(cj->first.begin(), cj->first.end()); ci->second.insert(cj->second.begin(), cj->second.end()); c.erase(cj); } for (i = 0; i <= p1+p2; i++) { table[0][i] = 0; } table[0][0] = 1; k = 1; for (list < pair< set, set > >::iterator p = c.begin(); p != c.end(); p++, k++) { for (i = 0; i <= p1+p2; i++) { table[k][i] = 0; which[k][i] = 0; } for (i = 0; i <= p1+p2; i++) { if (table[k-1][i] == 0) { continue; } j = i + p->first.size(); table[k][j] += table[k-1][i]; if (table[k][j] > 2) { table[k][j] = 2; } which[k][j] = +i+1; j = i + p->second.size(); table[k][j] += table[k-1][i]; if (table[k][j] > 2) { table[k][j] = 2; } which[k][j] = -i-1; } } if (table[c.size()][p1] == 2) { cout << "no" << endl; } else { set result; result.clear(); k = c.size(); j = p1; for (list < pair< set, set > >::reverse_iterator p= c.rbegin(); p != c.rend(); p++) { if (which[k][j] > 0) { result.insert(p->first.begin(), p->first.end()); j = which[k][j] - 1; } else if (which[k][j] < 0) { result.insert(p->second.begin(), p->second.end()); j = (-which[k][j]) - 1; } k--; } for (set::iterator p = result.begin(); p != result.end(); p++) { cout << *p << endl; } cout << "end" << endl; } } return 0; }