The Merger
The University of Adelaide and the University of South Australia are merging! To manage the growing cohort of computer science students, you must assign each student's classes to one of two campuses.
To minimize disruption to student life, students can make either of two types of requests:
LOVE
: The student names two peers. They want both of them assigned to the same campus as themselves.HATE
: The student names two peers. They want both of them to be assigned to a different campus than themselves.
Given a list of students and their requests, is it possible to assign everyone to campuses in a way that satisfies all of these constraints?
Input
The first line consists of an integer
, the number of requests.
The next lines contain
,
,
, and
, where:
is the name of the student making the request.
is either:
LOVE
, indicating that studentwants to be assigned to the same campus as both
and
.
HATE
, indicating that studentwants to be assigned to a different campus than both
and
.
.
.
Output
Output "Yes" if it is possible to assign the students to campuses so that everyone's requests can be fulfilled. Otherwise, output "No".
Clarifications
- Some students may choose not to make a request.
- Some students can make more than one request.
- All requests are unique.
Example
Input 1
6
Tom LOVE Shayla Jack
Irhas HATE Maged Tom
Kevin LOVE Tim Patrick
Shayla LOVE Tom Ray
Ray HATE Tim Kevin
Tim HATE Tom Jack
Output 1
Yes
- Tom, Jack, Shayla, Maged, Ray
- Irhas, Tim, Patrick, Kevin
Everyone is happy:
- Tom is happy because they are with Shayla and Jack.
- Irhas is happy because he is not with Tom or Maged.
- Kevin is happy because he is with Tim and Patrick.
- Shayla is happy because they are with Tom and Ray.
- Ray is happy because he not with Tim and Kevin.
- Tim is happy because he is not with Tom and Jack.
Input 2
2
A LOVE B C
A LOVE D E
Output 2
Yes
Everyone is happy, and they can all go to the same campus.
Input 3
3
A HATE B C
B HATE A C
C HATE A B
Output 3
No
Everyone hates each other, so no two people can be on the same campus.
Input 4
6
A LOVE B C
A LOVE B C
A LOVE B C
B HATE C D
D LOVE C E
E HATE B A
Output 4
No
Comments