Description
There are two kinds of people living on an island, those who are good and those who are bad.
A good man always speaks the truth, and a bad man always lies.
Each member on the island has an integer number to distinguish each member like ID.
Now you have n opportunities to ask questions, but the content of the question can only be to ask one resident whether the other resident is a good person, please determine the identity of each resident according to the collected answers.
Input
The input contains multiple sets of test cases.
The first line of each set of test cases contains three non-negative integers N,P1 and P2, where N is the total number of times you can ask questions, P1 isthe total number of good people, and P2 is the total number of bad people.
The next n lines each contain two integers xi, yi and a string Ai, where xi, yi is thenumber of the people on the island, and you're going to ask the people numbered xi whether the people numbered yi are good people,
ai is his answer, if ai is "yes", he answers you "yes", if ai is "no", he answers you "no".
xi,yi might be the same, which means you're asking whether the person is a good person.
When the input is a "0, 0, 0" on one line, the input is terminated.
Datarange:1≤xi,yi≤p1+p2,1≤n<1000,1≤p1,p2<300
Output
For each set of test cases, if the query yields enough information for you to determine the identity of each resident, output the Numbers of all the good people on oneline, and then "end" on another line to indicate the end of the use case output.
If the information obtained is insufficient to determine the identity of each resident, then "no" is output, which also occupies one line.
Sample Input 1
2 1 1
1 2 no
2 1 no
0 0 0
Sample Output 1
no
Sample Input 2
2 2 1
1 2 yes
2 3 no
0 0 0
Sample Output 2
1
2
end
Personal Answer (using language:JAVA) Not necessarily right
public class Main {
public static void main(String[] args) {
System.out.println("Unsolved");
}
}
Welcome to communicate!