Cycle detection in Directed Graph

In this code we are stating from 0, but the input that we take there indegree of 0 is 0, but what if the indegree of 0 is not 0, then this code will fail i think, so what is the new approach.

Hello @apoorv_tg could you please share any such input in which you have doubt in which it will fail we can discuss that.
that will be more explainable.