2
def maximumInvitations(self, favorite: List[int]) -> int:8
def get_max_len_cycle(cur):10
inpath[cur], visited_time[cur], nxt = True, cur_time, favorite[cur]12
ret = 0 if not inpath[nxt] else visited_time[cur] - visited_time[nxt] + 113
if visited_time[nxt] == 0:14
ret = max(ret, get_max_len_cycle(nxt))20
if visited_time[i] == 0:21
ret_cycle = max(ret_cycle, get_max_len_cycle(i))24
back_edge_graph = [[] for _ in range(n)]26
back_edge_graph[favorite[i]].append(i)28
def get_max_depth(cur):30
for nxt in back_edge_graph[cur]:31
if favorite[cur] != nxt:32
ret = max(ret, get_max_depth(nxt) + 1)36
if favorite[favorite[i]] == i:37
ret_not_cycle += get_max_depth(i) + 139
ret = max(ret_cycle, ret_not_cycle)