indegree to keep track of the indegree of each node.visited array to mark nodes that have been visited.q and a stack s to process nodes.indegree array by counting the number of incoming edges for each node.indegree of 0 to the queue q.s.s to calculate the number of nodes visited for nodes not in cycles.