#C14234. User Permissions Aggregator

    ID: 43861 Type: Default 1000ms 256MiB

User Permissions Aggregator

User Permissions Aggregator

Given a user identifier, role assignments, and a mapping of roles to permissions, determine the unique permissions for the user. You are provided with three pieces of input data:

  • An integer representing the user ID.
  • A set of role assignment entries which map users to roles.
  • A permissions mapping that associates each role with a list of permission strings.

Your task is to compute the union of permissions for all roles assigned to the given user. In mathematical terms, if R(u) is the set of roles for user u, and for each role r, P(r) is the set of permissions, then the output is:

$$ \bigcup_{r \in R(u)} P(r) $$

The final output should be a space-separated list of unique permissions sorted in lexicographical order. If the user has no roles or the roles do not match any in the permissions mapping, output an empty line.

inputFormat

Input is read from standard input. The format is as follows:

  1. The first line contains an integer representing the user ID.
  2. The second line contains an integer N, the number of role assignment entries.
  3. The next N lines each contain an integer uid, followed by an integer K (the number of roles for that user), and then K role names.
  4. After that, a line containing an integer M is provided, representing the number of roles in the permissions mapping.
  5. The next M lines each start with a role name, followed by an integer L (the number of permissions for that role), and then L permission strings.

outputFormat

Output a single line containing the lexicographically sorted unique permissions for the given user, separated by a space. If the user has no permissions, output an empty line.## sample

1
3
1 1 admin
2 2 editor viewer
3 1 viewer
3
admin 3 read write delete
editor 2 read write
viewer 1 read
delete read write