← 返回 google 的题目列表Maintain manager/peer relationships and answer is_manager queries
类型:online_judge
You are given a sequence of operations/queries about employee relationships. Maintain the relationships and answer manager queries.
There are three operations:
manager a b: means a is the manager of b (create a directed relationship “a manages b”).
peer a b: means a and b are peers, i.e., they share the same manager.
is_manager a b: query whether a is the manager of b. Output true if yes, otherwise false.
Process the operations in order; whenever you see an is_manager query, output one line.
Input
First line: integer n number of operations.
Next n lines: one of
manager a b
peer a b
is_manager a b
Output
For each is_manager a b, print true or false on its own line.
Notes
Employee IDs are strings without spaces.
Operations can appear in any order; you may see peer before anyone’s manager is known.
You should handle incremental information completion (e.g., peers established first, then a manager is assigned to one peer).
Example
Input
6
manager A B
peer B C
is_manager A C
is_manager C A
manager D E
is_manager D E
Output
true
false
true