Two parties P82271


Statement
 

pdf   zip

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

Input consists of several cases, each with the number of friends aa, followed by their aa names, all different and in any order. Follow the number of hate relationships mm, and the mm pairs of friends xx and yy that hate each other.

Suppose 2a1042 \le a \le 10^4, that the names are words with between one and six lowercase letters, 1m5a1 \le m \le 5a, xyx \ne y, that both xx and yy appear in aa’s friends list, and that no hate relationship appears more than once.

Output

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.

Public test cases
  • Input

    5 edgar tomas omer anna ivet
    4
    anna tomas
    omer anna
    edgar ivet
    edgar anna
    
    3 x y z
    3
    x y
    y z
    x z
    
    3 a b c
    1
    c a
    

    Output

    SI anna ivet
    NO
    SI a b
    
  • Information
    Author
    Salvador Roura
    Language
    English
    Translator
    Salvador Roura
    Original language
    Catalan
    Other languages
    Catalan
    Official solutions
    C++
    User solutions
    C++