#K2191. Employee Task Hierarchy
Employee Task Hierarchy
Employee Task Hierarchy
You are given n employees numbered from 1 to n. Each employee i is assigned a unique task identified by an integer t_i. Additionally, each employee has a list of direct subordinates. An employee is responsible for his/her own task as well as the tasks of all subordinates (both direct and indirect). Your task is to compute, for each employee, the sorted list (in ascending order) of all tasks under his/her responsibility.
The relationship is provided in the following format:
- The first line contains the integer n.
- The second line contains n space-separated integers where the i-th integer represents the task t_i for employee i.
- The following n lines each start with an integer k (the number of direct subordinates for the employee) followed by k space‑separated integers representing the IDs of these subordinates. (Note: IDs are 1-indexed.)
For example, consider n = 3
, tasks 101 202 303
and the following subordinate lists:
2 2 3 0 0
Employee 1 manages employees 2 and 3, so his responsibilities include tasks 101, 202, and 303. Employee 2 and Employee 3 have no subordinates, so they are each responsible only for their own tasks.
Note: Ensure that your output exactly matches the required format.
inputFormat
The first line contains a single integer n
representing the number of employees.
The second line contains n
space‑separated integers representing the tasks assigned to each employee (t_1, t_2, ..., t_n
).
Then follow n
lines. The i-th of these lines begins with an integer k
, the number of direct subordinates of employee i, followed by k
space‑separated integers indicating the 1‑indexed IDs of the subordinates.
outputFormat
Output n
lines. The i-th line should contain the sorted list (in ascending order) of tasks that employee i is responsible for. Separate the integers with a single space.
3
101 202 303
2 2 3
0
0
101 202 303
202
303
</p>