#P3450. Birthday Party Guest Selection

    ID: 16705 Type: Default 1000ms 256MiB

Birthday Party Guest Selection

Birthday Party Guest Selection

Little Sophie is organizing a birthday party and wants to invite as many of her kindergarten friends as possible. However, each friend may have their own demands regarding who they do not want to see at the party. For instance, one friend may only attend if two other friends are not invited, while another may refuse to see anyone except a specific group. The party is considered a success if for every invited guest, none of the guests they object to are present.

Sophie has a list of n acquaintances and a requirement to invite at least \( k \) kids. In addition, there are several demands of the form "if friend a is invited, then friend b must not be invited." Sophie's goal is to choose the largest possible group of guests such that no invited guest has any objection within the group. If it is not possible to invite at least \( k \) kids, she will not hold the party at all.

Your task is to help Sophie decide whether a successful party can be held, and if so, to output one of the largest possible groups of kids satisfying the demands.

inputFormat

The input consists of multiple lines:

  • The first line contains three integers \( n \), \( k \) and \( m \) where \( n \) (\(1 \le n \le 20\)) is the total number of kids, \( k \) is the minimum number of kids required for the party (\( k \le n \)), and \( m \) is the number of demand rules.
  • The following \( m \) lines each contain two integers \( a \) and \( b \) (1-indexed) representing a demand: if kid \( a \) is invited then kid \( b \) must not be invited.

All numbers are separated by spaces or newlines.

outputFormat

If it is impossible to select at least \( k \) kids such that all demands are satisfied, print NIE (which means "no" in Polish). Otherwise, print the list of invited kids (their indices in increasing order) separated by spaces. If there are multiple solutions, output any one of them.

sample

4 3 2
1 2
1 3
2 3 4