I checked most of the DFS solutions, they set the visited[i] to true when entering the function and reset it to false when leaving. Then they use each node as the starting node of the DFS call.
Now consider these courses:
0->1->2->3->4->5-> ... -> n-1, where a->b means a is b's prerequisite. (actually the inverse is fine)
starting from 0 we visited n the nodes. Then we start from 1, we visited n-1 nodes. Total is n(n+1)/2 , O(n^2) or you can say O(E^2)
I believe, in this post, @joyjoyshu 's solution solved your problem by seeting visited[node]
@baihuajun24 setting visited[node] = 2
Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.