You want to throw a party with all your friends, but unfortunately some of them hate each other. So you decide to make two parties instead of one, inviting each friend to exactly one party, and avoiding two people who hate each other going to the same party. Can you do it?
Input consists of several cases, each with the number of friends , followed by their names, all different and in any order. Follow the number of hate relationships , and the pairs of friends and that hate each other.
Suppose , that the names are words with between one and six lowercase letters, , , that both and appear in ’s friends list, and that no hate relationship appears more than once.
Print one line for each case. If there is no solution, print
“NO”. Otherwise, print “SI” followed by the
names of the participants in either party, in any order. If there is
more than one solution, choose anyone. Follow the format of the examples
exactly.
Author: Unknown
Translator: Salvador Roura
Event: Examen extraordinari d’Algorísmia, FME
Date: 2017-06-27
Generation: 2026-07-02T12:03:02.733Z
© Jutge.org, 2006–2026.
https://jutge.org