#K54882. Tournament Rankings Simulation

    ID: 29852 Type: Default 1000ms 256MiB

Tournament Rankings Simulation

Tournament Rankings Simulation

You are given a round-robin tournament among N players. In the tournament, some matches have already been played. A match between two players is played only once. In each match, if one player scores more than the other, the winner gets 2 points and the loser gets 0 points; if the scores are equal, both players receive 1 point.

After the already played matches, simulate all possible outcomes of the remaining matches. For each complete simulation, determine the ranking of a specified target player. The ranking is determined by sorting the players by the following criteria (in order):

  • Higher total points
  • Fewer losses
  • More wins
  • Lexicographical order of names (ascending)

Your task is to output all distinct possible rankings (in ascending order) for the target player, assuming every possible outcome (win, lose, draw) for each remaining match.

inputFormat

The input is read from standard input and has the following format:

N
player_1
player_2
... (N players total)
M
match_1
match_2
... (M matches played)
target_player

Each match is provided in the format: Player1 Score1 - Score2 Player2.

outputFormat

Output a single line containing the distinct possible rankings (in ascending order) that the target player can achieve, separated by a single space.

## sample
4
ALF
BOB
CAT
DAN
3
ALF 2 - 1 BOB
BOB 1 - 1 CAT
CAT 0 - 0 DAN
ALF
1 2 3 4