Soccer table P86236


Statement
 

pdf   zip

thehtml

You are a sports journalist that is in charge of the soccer matches in your newspaper. The editor has asked you for printing all the results of the played matches to date. However, your lack of organization is about to play a dirty trick on you: you do not find the file where yo have stored all the results! You only know the number of points that every team has won (0 for a lost, 1 for a tie, and 3 for a won match), and the played matches to date. Write a program that indicates the result of each one of the played games.

Input

For each case consists of two natural numbers, M≤ 10 and N≤ 20, representing the number of teams in the league and the number of played matches, respectively. Then, M lines come with the names of the teams and the number of points that they have. Finally, N lines come, each one of them contains the number of two of the previous team, indicating than the two team have played a match between them. The input may contain various cases, separated by a line in white. A line with the number −1 indicates the end of the input.

Output

For each test data of the input, your program must print the result of all the matches in a line, separated by spaces. If the local team has won, it must print “1”: if the visiting team has won, print “2”; if there was a tie, print “X”. We assure you that each case only admits a solution.

Scoring

  • Test1:  ‍45 Points ‍

    Tests with no more than 20 cases with M≤ 6 y N≤ 10, as the ones in the instance 1.

  • Test2:  ‍55 Points ‍

    Tests with no more than 20 cases with M≤ 10 y N≤ 20, as the ones in the instance 2.

Public test cases
  • Input

    2 1
    Barcelona 1
    Madrid 1
    Barcelona Madrid
    
    2 1
    Barcelona 3
    Madrid 0
    Madrid Barcelona
    
    2 1
    Madrid 3
    Barcelona 0
    Madrid Barcelona
    
    4 4
    Barcelona 4
    Madrid 4
    Sevilla 2
    Getafe 0
    Barcelona Getafe
    Madrid Sevilla
    Sevilla Barcelona
    Getafe Madrid
    
    6 9
    Barcelona 6
    Valencia 4
    Madrid 4
    Deportivo 4
    Sevilla 3
    Betis 3
    Barcelona Deportivo
    Valencia Deportivo
    Valencia Barcelona
    Betis Sevilla
    Madrid Deportivo
    Sevilla Madrid
    Betis Deportivo
    Madrid Betis
    Betis Valencia
    
    6 10
    Madrid 8
    Barcelona 8
    Valencia 4
    Sevilla 4
    Deportivo 2
    Betis 0
    Madrid Deportivo
    Barcelona Sevilla
    Betis Madrid
    Betis Sevilla
    Barcelona Deportivo
    Betis Barcelona
    Madrid Barcelona
    Sevilla Deportivo
    Deportivo Valencia
    Madrid Valencia
    
    -1

    Output

    X
    2
    1
    1 X X 2
    1 1 2 2 2 2 X X X
    1 1 2 2 X 2 X X 2 X
    
  • Input

    10 18
    Deportivo 11
    Betis 9
    Sevilla 6
    AtlMadrid 6
    Barcelona 5
    AthBilbao 4
    Madrid 2
    Espanyol 2
    Valencia 1
    RealSociedad 1
    Deportivo RealSociedad
    Barcelona AtlMadrid
    AthBilbao Espanyol
    AtlMadrid Madrid
    Deportivo Madrid
    Betis Deportivo
    RealSociedad Espanyol
    Valencia Deportivo
    Deportivo Barcelona
    Madrid Barcelona
    Espanyol Sevilla
    Sevilla AtlMadrid
    Madrid Betis
    Valencia AthBilbao
    Betis AthBilbao
    Valencia AtlMadrid
    RealSociedad Betis
    Barcelona Betis
    
    -1

    Output

    1 1 X 1 1 X X X 1 X 2 1 X 2 1 2 2 X
    
  • Information
    Author
    Anders Jonsson
    Language
    English
    Translator
    Carlos Molina
    Original language
    Spanish
    Other languages
    Spanish
    Official solutions
    C++
    User solutions
    C++