#K94182. Finding Supervisors Receiving Reports

    ID: 38585 Type: Default 1000ms 256MiB

Finding Supervisors Receiving Reports

Finding Supervisors Receiving Reports

You are given an integer \(N\) denoting the total number of employees and a list of \(N\) integers representing the supervisor of each employee. The list represents a company hierarchy where the supervisor of an employee is identified by a nonzero integer, and the CEO is represented by 0.

Your task is to identify all employees (supervisors) who directly receive reports from at least one employee. In other words, for every employee in the list you must record their supervisor, except for the CEO (denoted by 0). Finally, output the unique supervisor values in sorted order.

For example, if \(N=7\) and the list of supervisors is [0, 1, 1, 3, 3, 4, 5], then the supervisors receiving reports are 1, 3, 4, and 5.

Note: The output should be printed on a single line with each number separated by a space. If there is no supervisor (i.e. all employees are CEOs or there are no reports), print an empty line.

inputFormat

The first line of input contains a single integer \(N\) indicating the number of employees.

The second line contains \(N\) space-separated integers where each integer represents the supervisor of the corresponding employee. The value 0 indicates that the employee is the CEO.

outputFormat

Output a single line with the sorted, space-separated list of supervisors who receive reports. If no employee receives a report (i.e. no supervisor other than 0 exists), output an empty line.

## sample
7
0 1 1 3 3 4 5
1 3 4 5