You are given a role hierarchy represented as a directed acyclic graph (DAG). Roles are numbered 0 to n-1. An array grants contains edges [from, to] meaning role to inherits privileges from role from. Each role i has an allowedList[i] (privileges explicitly granted) and a disallowedList[i] (privileges explicitly blocked). Inheritance…