#C747. File Access Delegation
File Access Delegation
File Access Delegation
You are given a set of delegation rules that define which employee can delegate file access rights to another employee. Each rule is represented as a triple of strings (sender, receiver, file). Access rights to a particular file can be passed from one employee to another through direct or indirect delegation. Given a list of rules and a query consisting of an employee and a file name, determine whether the queried employee can obtain access to the file through any chain of delegations. Print YES
if access is granted and NO
otherwise.
Note: The delegation chain is only considered for the specific queried file. There may be cycles in the delegation rules; your solution should avoid infinite loops.
Example: If the rules are:
- Alice delegates to Bob for Report1
- Bob delegates to Charlie for Report1
Then for the query Charlie Report1
, the answer is YES
.
inputFormat
The input is given via standard input (stdin) and has the following format:
M sender1 receiver1 file1 sender2 receiver2 file2 ... (M lines in total) query_employee query_file
Where:
M
is an integer representing the number of delegation rules.- Each of the next M lines contains three strings: the delegator's name, the delegate's name, and the file name.
- The last line contains two strings: the employee to query and the file name.
outputFormat
Output a single line to standard output (stdout): YES
if the employee can get access to the file (directly or through a chain of delegations), otherwise print NO
.
1
Alice Bob Report1
Bob Report1
YES