Your school has decided to organize a research trip for a class of students numbered from to . Unfortunately, organizing trips are not easy as it seems, as there are rules that need to be followed in order for the trip to happen. The rules come in four different forms:
||Students and are friends and either they both go on the trip, or they both do not go on the trip|
||Students and are enemies and at most one of them can go on the trip|
||Students and are research partners and the lab instructor would like exactly one of them to go on the trip|
||Students and are in a study group and at least one of them should go on the trip|
In addition, there are students who must go on the trip no matter what. Can you determine if the school trip will happen? The trip will only happen if all the rules are followed.
For this problem, you will NOT be required to pass all the samples in order to receive points. In addition, all subtasks are disjoint, and you are NOT required to pass previous subtasks to earn points for a specific subtask.
||All rules will be |
||All rules will be |
For all subtasks:
The first line contains 3 integers, , , and .
The next lines contain the numbers of the students who must go on the trip. Each line contains a single integer between and . It is guaranteed that these integers are pairwise distinct.
The next lines describe the rules. Each line will be in the format specified above. Specifically, each line will contain the name of the rule, followed by 2 integers and , describing the students the rule applies to.
This problem is graded with an
identical checker. This includes whitespace characters. Ensure that every line of output is terminated with a
\n character and that there are no trailing spaces.
YES if all the rules are followed and the school trip happens and
If and only if the answer is
YES, on the next line, print a string of characters, consisting of only
?s. If the student is definitely going on the trip, then the character is
1. If the student is definitely not going on the trip, then the character is
0. Otherwise, if it cannot be determined whether the is going on the trip or not, then the character is
If (and only if) the answer is
NO, then do not print anything else.
Sample Input 1
3 3 1 1 GROUP 1 2 GROUP 1 3 ENEMIES 2 3
Sample Output 1
Sample Explanation 1
Student must attend the trip. Either student or student can attend the trip (but not both), though it cannot be determined which one will be attending.
Sample Input 2
4 3 0 PARTNERS 1 2 PARTNERS 1 3 PARTNERS 4 2
Sample Output 2
Sample Explanation 2
Either students and will attend the trip, or students and will attend the trip, but it cannot be determined which two will be attending.
Sample Input 3
3 3 0 PARTNERS 1 2 PARTNERS 1 3 PARTNERS 3 2
Sample Output 3
Sample Input 4
4 6 1 4 PARTNERS 1 3 PARTNERS 3 4 PARTNERS 4 2 PARTNERS 2 1 FRIENDS 2 3 FRIENDS 4 1
Sample Output 4
Sample Explanation 4
For all students, it can be determined for sure whether they will attend the trip or not.