There is a directed graph consisting of n nodes labeled from n i has exactly one outgoing directed edge to edges[i].
Starting from a node i, the process moves along the graph by continually following the outgoing edges until a node that has already been visited during the current traversal is reached.
Return an array ans of size n, where ans[i] is the total number of distinct nodes visited when beginning the traversal from node i.
Constraints:
n edges.length
n
edges[i] n
edges[i] i
There is a directed graph consisting of n nodes labeled from n i has exactly one outgoing directed edge to edges[i].
Starting from a node i, the process moves along the graph by continually following the outgoing edges until a node that has already been visited during the current traversal is reached.
Return an array ans of size n, where ans[i] is the total number of distinct nodes visited when beginning the traversal from node i.
Constraints:
n edges.length
n
edges[i] n
edges[i] i