1
# Runtime: 254 ms (Top 40.58%) | Memory: 15.6 MB (Top 60.31%)3
# Definition for Employee.5
def __init__(self, id: int, importance: int, subordinates: List[int]):7
self.importance = importance8
self.subordinates = subordinates13
def dfs(self, graph, employees, empId, totalImportance, visited):14
totalImportance += graph[empId][0]17
for neighbour in graph[empId][1]:18
if neighbour not in visited:19
totalImportance = self.dfs(20
graph, employees, neighbour, totalImportance, visited23
return totalImportance25
def getImportance(self, employees: List["Employee"], id: int) -> int:28
for employeeInfo in employees:29
empId, importance, suboordinates = (31
employeeInfo.importance,32
employeeInfo.subordinates,34
graph[empId] = [importance, suboordinates]38
if graph[id][1] == []:43
totalImportance = self.dfs(graph, employees, id, totalImportance, visited)45
return totalImportance