Communication in employee hierarchy
Assignment
A large transnational company is analyzing its organizational structure. One of the investigated phenomena is so called Hierarchy communication scheme.
The company is ruled by one general director. Each employee other than the general director has exatly one direct supervisor and any number of direct subordinates. General director has no direct supervisor. In the Hiearchy communication scheme, each employee exchanges information only with his/her direct supervisor or direct subordinate.
We define the communication distance between two employees A and B as the minimum number of employees involved in information exchange between A and B when the Hiearchy communication scheme is used. The communication distance includes both employees A and B. The communication is considered to be easy when all employees involved in the communication share the same mother language.
The company wants to know what is the maximum easy communication distance, i.e. what is the maximum communication distance for which all employees involved in the communication share the same mother language.
The task
You are given the hierarchy structure of the company and the mother language of each employee. You have to determine the maximum easy communication distance in the company and list all languages in which it is attained.
Input
The input text file describes the company hierarchy and the mother languages of the employees.
Each employee is represented in the format:
L (
direct_subordinate_1
direct_subordinate_2
...
direct_subordinate_n
)
L is a positive integer which identifies the mother language of the employee.
The direct_subordinate_i field represents the i-th direct subordinate of the employee.
The indentation of any employee’s direct subordinate is bigger by one space than the indentation of the employee.
The whole input is a representation of the general director, all other employees representations are defined by recursive application of the format rule described above (see also the examples).
Each value of L is restricted by the inequality 1 ≤ L ≤ 30. The number of employees does not exceed 4.1×106.
Output
The output consists of two text lines. The first line contains the number equal to the maximum easy communication distance in the company. The second line contains the identifiers of all languages in which the maximum easy communication distance is attained in the company. The identifiers are sorted in ascending order and are separated by spaces.
Public data
The public data set is intended for easier debugging and approximate program correctness checking. The public data set is stored also in the upload system and each time a student submits a solution it is run on the public dataset and the program output to stdout and stderr is available to him/her.