ACM Eastern European Regional Programming Contest.
Bucharest, Romania
October 19, 1996

Problem B
Working with Relations

Input File Name: B.DAT

Program Source File: B.PAS or B.C or B.CPP


The wages of the employees of a company are computed on the basis of a set of relative rankings of the form x R y, where x and y are names and/or numbers, and R is a relational operator from the set { <, <=, >, >=, = }. The meaning of x R y is:

the salary of x | | the salary of y

| must be in relation R with |

number x | | number y


The problem is to compute the minimum and the maximum wage which each of the employees can get according to a given set of relations. It is known that: the name of an employee is at most 8 characters long; the wages are integers from 1 to 99999; only integer numbers appear in relations; the number of employees cannot exceed 100 and the number of relations is at most 1000.




Figure 1. Input and output samples of the program

The program input is from a file which contains several sets of relations as shown in figure 1. The relations of a set are one on a line and their elements are separated by spaces. Each set of relations ends with a line which contains a minus sign only. The format of input data is correct.


The result of the program is on standard output. For each consistent set of relations the result is the message OK followed by the list of employees (if any), in alphabetical order, together with their minimum and maximum wages as shown in figure 1. If a set of relations is inconsistent then the message No solution is printed for that set. Notice that for a set of relations which contains only numbers the result can be either the message OK or No solution.