#C14473. Organizational Chart: Find Manager
Organizational Chart: Find Manager
Organizational Chart: Find Manager
You are given an organizational chart represented as a list of direct reporting relationships. Each relationship is given as a pair of strings where the first string is the manager and the second string is their direct subordinate. Your task is to determine the direct manager of a queried employee.
If the employee is not found in any subordinate list or is the top-level manager (i.e., does not have a manager), print None
.
Note: The input guarantees that if an employee has a manager, it appears exactly once as a subordinate in the input relationships.
The relationship can be thought of as a tree where the root node (e.g., the CEO) has no manager. Formally, if we denote the set of relationships by \(R\), then for a queried employee \(E\), if there exists a pair \((M, E) \in R\), output \(M\); otherwise, output None
.
inputFormat
The input is read from standard input (stdin) and has the following format:
<employee> <N> <manager1> <subordinate1> <manager2> <subordinate2> ... (total N lines of relationships)
Where:
<employee>
is the name of the employee whose manager is to be found.<N>
is the number of direct reporting relationships.- Each subsequent line contains two strings separated by space representing the manager and their direct subordinate.
outputFormat
Output the name of the direct manager of the queried employee to standard output (stdout). If the employee does not have a manager or is not found in any relationship, output None
.
Dev1
5
CEO CTO
CEO CFO
CTO Dev1
CTO Dev2
CFO Acc1
CTO