#C6457. Employee Management Hierarchy
Employee Management Hierarchy
Employee Management Hierarchy
You are given a list of employee records. Each record consists of an employee ID, a supervisor ID, the number of departments the employee is associated with, followed by the names of these departments.
Your task is to build an organizational hierarchy where:
- The supervisor of an employee is indicated by the supervisor ID. A supervisor ID of -1 indicates that the employee has no supervisor.
- Each employee’s record should display the supervisor, a list of department names (formatted as a Python list, e.g.,
['HR', 'Finance']
), and a list of immediate subordinates (sorted in ascending order by employee ID).
The final output should list each employee's information in ascending order of their employee IDs.
Note: When writing mathematical formulas, please use the LaTeX format, e.g., \(a+b\).
inputFormat
The input is read from stdin and has the following format:
n record_1 record_2 ... record_n
Where:
n
: an integer representing the number of employees.- Each
record
is a space-separated string containing: - Employee ID (integer)
- Supervisor ID (integer, -1 if none)
- The number of departments (integer)
- List of department names (strings)
outputFormat
The output should be printed to stdout. For each employee, print a line in the following format:
employee X: supervisor = Y, departments = [dept1, dept2, ...], subordinates = [sub1, sub2, ...]
Where:
X
is the employee ID.Y
is the supervisor ID.- The departments are displayed as a Python list with single quotes around each department name.
- The subordinates list (if any) is sorted in ascending order.
5
0 -1 2 HR Finance
1 0 1 IT
2 0 1 HR
3 1 2 IT Marketing
4 1 1 Finance
employee 0: supervisor = -1, departments = ['HR', 'Finance'], subordinates = [1, 2]
employee 1: supervisor = 0, departments = ['IT'], subordinates = [3, 4]
employee 2: supervisor = 0, departments = ['HR'], subordinates = []
employee 3: supervisor = 1, departments = ['IT', 'Marketing'], subordinates = []
employee 4: supervisor = 1, departments = ['Finance'], subordinates = []
</p>