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:
Input Format | Description |
---|---|
FRIENDS a b |
Students |
ENEMIES a b |
Students |
PARTNERS a b |
Students |
GROUP a b |
Students |
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.
Constraints
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.
Subtask | Points | Additional Constraints | |
---|---|---|---|
None | |||
All rules will be PARTNERS rules | |||
All rules will be FRIENDS or PARTNERS rules | |||
None | |||
None |
For all subtasks:
Input Specification
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 contains the name of the rule, followed by 2 integers
and
, describing the students the rule applies to.
Output Specification
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.
Output YES
if all the rules are followed and the school trip happens and NO
otherwise.
If and only if the answer is YES
, on the next line, print a string of characters, consisting of only
0
s, 1
s, and ?
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
YES
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
YES
????
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
NO
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
YES
1001
Sample Explanation 4
For all students, it can be determined for sure whether they will attend the trip or not.
Comments