#K82157. Elimination Order in a Knockout Tournament

    ID: 35913 Type: Default 1000ms 256MiB

Elimination Order in a Knockout Tournament

Elimination Order in a Knockout Tournament

You are given a knockout tournament in which each match eliminates one player. The tournament is played in rounds. In each round, a number of matches are played; each match is represented by two strings: the winner and the loser. The elimination order is the order in which players lose any of these matches. Your task is to determine and output the elimination order.

Note: If no matches are played, there will be no output.

The input and output follow the format described below.

Mathematically, if there are \(n\) players and \(r\) rounds, and each round \(i\) has \(m_i\) matches, then the elimination order is defined as the sequence of losers over all rounds. That is, if for round \(i\), the set of matches is \((w_{i,1}, l_{i,1}), (w_{i,2}, l_{i,2}), \ldots, (w_{i,m_i}, l_{i,m_i})\), then the elimination order is:

[ \text{Elimination Order} = \Big[ l_{1,1}, l_{1,2}, \ldots, l_{1,m_1}, l_{2,1}, \ldots, l_{r,m_r}\Big] ]

inputFormat

The input is given from standard input (stdin) and has the following format:

  1. An integer n representing the number of players.
  2. A line containing n space-separated strings, representing the names of the players.
  3. An integer r representing the number of rounds.
  4. For each round:
    1. An integer m indicating the number of matches in that round.
    2. m lines follow, each containing two space-separated strings: the winner's name and the loser's name.

outputFormat

Output the names of the eliminated players in the order they were eliminated. Each name should be printed on a new line. If no matches are played, output nothing.

## sample
8
Alice Bob Charlie David Eve Frank Grace Helen
3
4
Alice Bob
Charlie David
Eve Frank
Grace Helen
2
Alice Charlie
Eve Grace
1
Alice Eve
Bob

David Frank Helen Charlie Grace Eve

</p>