#K88137. Project Assignment System
Project Assignment System
Project Assignment System
You are tasked with building a project assignment system for a company. In this system, employees are assigned to projects, and the system should be able to answer queries about the assignments.
The system supports the following commands:
- assign <employee_name> <project_name>: Assigns an employee to a project. If either the employee or project does not exist, they should be added to the system.
- employees <project_name>: Returns a list of employees assigned to the specified project, sorted in lexicographical order. If the project does not exist, return an empty line.
- projects <employee_name>: Returns a list of projects that the specified employee is assigned to, sorted in lexicographical order. If the employee does not exist, return an empty line.
The input will start with an integer n denoting the number of commands. Each of the next n lines contains one command. For every query command (i.e. commands starting with employees
or projects
), you should print the result on a new line. The elements in the result should be separated by a single space. If there is no result for the query, output an empty line.
For example, if the input is:
7 assign alice project1 assign bob project1 assign alice project2 assign charlie project1 employees project1 projects alice projects bob
Then the output should be:
alice bob charlie project1 project2 project1
Ensure your solution handles the commands correctly and is efficient and correct for all valid inputs. In mathematical terms, if we denote the set of employees assigned to a project P as \(E(P)\), then your solution should output \(\text{sort}(E(P))\) for the query employees P
, and similarly for projects assigned to an employee \(e\), output \(\text{sort}(P(e))\) for projects e
.
inputFormat
The first line of the input contains an integer n (1 ≤ n ≤ 105), which represents the number of commands. The following n lines each contain a command in one of the following formats:
assign <employee_name> <project_name>
employees <project_name>
projects <employee_name>
All names are non-empty strings without spaces.
outputFormat
For every command that starts with employees
or projects
, output a single line containing a space-separated list of names in lexicographical order. If there are no employees or projects to output, print an empty line.
7
assign alice project1
assign bob project1
assign alice project2
assign charlie project1
employees project1
projects alice
projects bob
alice bob charlie
project1 project2
project1
</p>