#C5997. Employee Hierarchy Sorted Listing

    ID: 49707 Type: Default 1000ms 256MiB

Employee Hierarchy Sorted Listing

Employee Hierarchy Sorted Listing

You are given an employee tree in JSON format representing an organization. Each employee is represented as an object with the following fields:

  • id: a unique integer identifying the employee.
  • name: a string representing the employee's name.
  • subordinates: an array of employee objects who report directly to this employee.

Your task is to traverse the entire hierarchy starting from the root employee, collect every employee's id and name, and then output the complete list sorted in ascending order by id. Formally, if the set of employees is \(E\) and each employee \(e \in E\) is represented by \(\{id, name\}\), you must output the list \(L = \{e | e \in E\}\) such that if \(e_i\) appears before \(e_j\) then \(e_i.id \leq e_j.id\). All formulas are formatted in \(\LaTeX\) as required.

inputFormat

The input is provided as a JSON string via standard input (stdin). This JSON object represents the root employee and follows the format:

{
  "id": integer,
  "name": string,
  "subordinates": [ employee objects ]
}

outputFormat

Output the list of employees as a JSON array to standard output (stdout). Each element in the array is an object containing just the id and name fields. The array must be sorted in ascending order by the id field. For example:

[{"id": 1, "name": "Alice"}, {"id": 2, "name": "Bob"}, ...]
## sample
{"id":1,"name":"Alice","subordinates":[]}
[{"id":1,"name":"Alice"}]