#K36902. Department Management Operations
Department Management Operations
Department Management Operations
This problem involves simulating operations on departments. Initially, you are given a list of departments with their respective employees. You must support transferring an employee from one department to another, merging two departments, listing all unique employees, and counting the employees in a particular department.
The operations are defined as follows:
- TRANSFER: Transfer an employee from one department to another.
- MERGE: Merge one department into another, transferring all employees. Formally, if \(D_{to}\) and \(D_{from}\) denote the employee sets of the two departments, then after merging: \(D_{to} = D_{to} \cup D_{from}\) and \(D_{from} = \emptyset\).
- LIST: List all unique employee IDs across all departments in ascending order.
- COUNT: Count the number of employees in a specified department, i.e. output \( |E_{dept}| \) for that department.
The operations are given in order and must be executed sequentially.
inputFormat
The input is read from stdin
with the following format:
n (n department lines) q (q operation lines)
Explanation:
- n: The number of departments.
- Each department line contains:
dept_id k employee_id[1] employee_id[2] ... employee_id[k]
, wherek
is the number of employees in that department. - q: The number of operations to perform.
- Each operation line is one of the following commands:
TRANSFER employee_id from_dept to_dept
MERGE from_dept to_dept
LIST
— Print the sorted list of unique employee IDs.COUNT dept_id
— Print the number of employees in the given department.
outputFormat
The output is printed to stdout
. For every LIST
or COUNT
operation encountered in the input, print the result on a separate line.
- For a
LIST
operation, output the sorted unique employee IDs separated by a single space. - For a
COUNT
operation, output a single integer representing the number of employees in that department.
3
1 3 1001 1002 1003
2 2 2001 2002
3 4 3001 3002 3003 3004
6
TRANSFER 1001 1 2
MERGE 2 1
LIST
COUNT 1
COUNT 2
COUNT 3
1001 1002 1003 2001 2002 3001 3002 3003 3004
5
0
4
</p>