Converging Maze: Largest Sum Cycle
You are given a maze with N cells. Each cell may have multiple entry points but not more than one exit (i.e. entry/exit points are unidirectional doors like valves).
The cells are named with an integer value from 0 to N-1.
You have to find:
The sum of the largest sum cycle in the maze. Return -1 if there are no cycles.
Sum of a cycle is the sum of the node number of all nodes in that cycle.
Input Format:
1. The first line has the number of cells N.
2. The second line has a list of N values of the edge[] array. edge[i] contains the cell number that can be reached from cell 'i' in one step. edge[i] is -1 if the 'i'th cell doesn't have an exit.
Output Format:
The first line denotes the sum of the largest sum cycle.
🤗 A very special thanks to a fantastic friend for all the help!