s
with all node indices and a deque dq
.dq
.s
and updating in-degrees until dq
is empty, leaving only cycle nodes in s
.res
with -1 for all nodes.s
(cycle nodes) to dq
and set their distance to 0 in res
.dq
, updating the distance for each node in res
.res
list containing the minimum distances.