#K66232. Employee Hierarchy Construction

    ID: 32375 Type: Default 1000ms 256MiB

Employee Hierarchy Construction

Employee Hierarchy Construction

You are given a list of employee-manager pairs. Each pair consists of an employee and his immediate manager. The CEO is indicated by the string None as the manager.

Your task is to build the employee hierarchy as a nested dictionary (or an equivalent data structure in other languages). In this hierarchy, each key is an employee and its corresponding value is a dictionary containing his direct subordinates. For example, given the list:

Alice None
Bob Alice
Charlie Alice
David Bob
Eve Charlie

the resulting hierarchy is:

{'Alice': {'Bob': {'David': {}}, 'Charlie': {'Eve': {}}}}

Note: If an employee has no subordinates, then his value will be an empty dictionary.

inputFormat

The input is read from stdin and is formatted as follows:

  • The first line contains an integer n, the number of employees.
  • The next n lines each contain two strings separated by a space: the employee name and the manager name. The manager name will be None if the employee is the CEO.

outputFormat

Print to stdout the hierarchy in a dictionary-like format that mirrors the nested structure as shown in the examples. Use single quotes for strings.

## sample
1
John None
{'John': {}}