#K80602. Organization Hierarchy Management

    ID: 35567 Type: Default 1000ms 256MiB

Organization Hierarchy Management

Organization Hierarchy Management

You are required to implement an organizational hierarchy management system. The system maintains a list of employees and their direct reporting relationships. Your program should support the following commands:

  • ADD name: Add an employee with the given name. Each employee's name is unique. No output is produced for this command.
  • ASSIGN employee_name manager_name: Assign manager_name as the direct manager of employee_name. Output True if the assignment is successful, or False if either employee does not exist or if the assignment would create a cyclic reporting relationship.
  • GET_MANAGER employee_name: Output the direct manager of the given employee_name. If the employee has no manager or does not exist, output None.
  • GET_TEAM manager_name: Output the names of employees who directly report to manager_name in alphabetical order, separated by a space. If there are no direct reports or the manager does not exist, output None.

Note: It is guaranteed that all names are strings without spaces. The program will read a series of commands from standard input and produce output to standard output accordingly.

inputFormat

The first line of the input contains an integer N that denotes the number of commands. The following N lines each contain one command. The commands can be one of the following: ADD name, ASSIGN employee_name manager_name, GET_MANAGER employee_name, or GET_TEAM manager_name.

outputFormat

For each command that requires an output (ASSIGN, GET_MANAGER, and GET_TEAM), print the corresponding result on a new line. For ASSIGN, print True or False. For GET_MANAGER, print the manager's name or None. For GET_TEAM, print the direct reports sorted in alphabetical order separated by a single space; if there are none, print None.

## sample
6
ADD Alice
ADD Bob
ASSIGN Bob Alice
GET_MANAGER Bob
GET_TEAM Alice
GET_TEAM Bob
True

Alice Bob None

</p>