private void dfs(Digraph G, int v)
	{
		marked[v] = true;
		onStack[v] = true;
		for (int w : G.adj(v))
		{
			if (hasCycle())
				return;
			else if (!marked[w])
			{
				edgeTo[w] = v;
				dfs(G, w);
			}
			else if (onStack[w])
			{
				cycle = new Stack<Integer>();
				for (int x = v; x != w; x = edgeTo[x])
					cycle.push(x);
				cycle.push(w);
				cycle.push(v); // starting and ending vertex of a cycle are the
								// same
			}
		}
		onStack[v] = false;
	}