#K94622. Employee Hierarchy Analysis

    ID: 38683 Type: Default 1000ms 256MiB

Employee Hierarchy Analysis

Employee Hierarchy Analysis

In this problem, you are given the hierarchy of employees in a company. Each employee is represented by a unique ID and may have a list of subordinate employees. Your task is to process the hierarchy and determine for each employee:

(\bullet) The number of direct subordinates. (\bullet) The total number of subordinates (both direct and indirect). (\bullet) Their level in the organizational hierarchy (with the CEO at level 0). (\bullet) Their role: if the employee is the head of the company (CEO), a Manager (has subordinates but not the CEO) or a Staff member (has no subordinates).

The input begins with an integer (n) denoting the number of employees, followed by (n) lines of employee information. Each line contains an employee ID and optionally a comma-separated list of subordinate IDs. The CEO is identified as the employee who is not listed as a subordinate in any record. Use this information to compute the required details and output one line per employee in the format:

employee {id}: direct_subordinates = {direct}, total_subordinates = {total}, level = {level}, {role}

Note that the total number of subordinates is the sum of all direct and indirect subordinates under an employee.

inputFormat

The input is read from standard input (stdin). The first line contains an integer (n) representing the number of employees. Each of the following (n) lines contains the employee information in the format:

id subordinate_list

Here, id is an integer representing the employee ID. subordinate_list is a comma-separated list of subordinate IDs. If an employee has no subordinates, the line will contain only the employee ID.

outputFormat

The output is written to standard output (stdout). For each employee (from 0 to (n-1)), output a line in the following format:

employee {id}: direct_subordinates = {direct}, total_subordinates = {total}, level = {level}, {role}

Here:

  • {direct} is the number of direct subordinates.
  • {total} is the total number of subordinates (direct and indirect).
  • {level} is the level in the hierarchy (CEO is level 0).
  • {role} is either "CEO", "Manager", or "Staff".## sample
3
0 1,2
1
2
employee 0: direct_subordinates = 2, total_subordinates = 2, level = 0, CEO

employee 1: direct_subordinates = 0, total_subordinates = 0, level = 1, Staff employee 2: direct_subordinates = 0, total_subordinates = 0, level = 1, Staff

</p>