#K69297. Employee Hierarchical Management System

    ID: 33055 Type: Default 1000ms 256MiB

Employee Hierarchical Management System

Employee Hierarchical Management System

You are required to implement an employee management system that supports several operations to manage employee records and their reporting hierarchy. In this system, each employee is uniquely identified by an integer ID and has a name. Every employee may have an immediate manager (another employee) except for the top-level manager, whose manager is defined as \( -1 \).

The system should support the following commands:

  • ADD id name: Add a new employee with the given id and name. The new employee does not have a manager initially.
  • SET_MANAGER employee_id manager_id: Set the manager of the employee with employee_id to the employee with manager_id.
  • GET_MANAGER employee_id: Print the immediate manager's id for the given employee. If the employee has no manager, print \( -1 \).
  • GET_REPORTS manager_id: Print the list of direct report IDs of the given manager, separated by a single space. If there are no reports, output an empty line.
  • GET_HIERARCHY_PATH employee_id: Print the hierarchical path of the given employee from the top-level manager to the employee. The path should be printed as a sequence of IDs separated by a single space.

The commands will be provided in the standard input. You need to process each command in the given order and output results for the commands that require printing.

inputFormat

The input will start with a single integer \( n \) (where \( n \geq 1 \)) that indicates the number of commands. This is followed by \( n \) lines, each containing one of the commands described above.

Example:

7
ADD 1 Alice
ADD 2 Bob
ADD 3 Charlie
GET_MANAGER 1
SET_MANAGER 2 1
GET_MANAGER 2
GET_HIERARCHY_PATH 2

outputFormat

For each command that requires an output (GET_MANAGER, GET_REPORTS, and GET_HIERARCHY_PATH), print the result on a new line. For GET_REPORTS and GET_HIERARCHY_PATH, the IDs should be printed in order separated by a single space.

For the sample above, the output should be:

-1
1
1 2
## sample
7
ADD 1 Alice
ADD 2 Bob
ADD 3 Charlie
GET_MANAGER 1
SET_MANAGER 2 1
GET_MANAGER 2
GET_HIERARCHY_PATH 2
-1

1 1 2

</p>