private void dfs(EdgeWeightedDigraph G, int v) {
    	onStack[v] = true;
    	marked[v] = true;

    	for (DirectedEdge e : G.outgoing(v)) {
    		if(e != null && !(e.isForbidden())){
    			if(e.weight() == 0){ // Visit the 0-weight edge

    				int w = e.to();

    				// short circuit if directed cycle found
    				if (cycle != null) return;

    				//found new vertex, so recur
    				else if (!marked[w]) {
    					edgeTo[w] = e;
    					dfs(G, w);
    				}

    				// trace back directed cycle
    				else if (onStack[w]) {
    					cycle = new Stack<DirectedEdge>();
    					while (e.from() != w) {
    						//Add the vertex in the cycle to a set
    						cycleSet.add(e.from());
    						e.setForbidden(true);
    						cycle.push(e);

    						e = edgeTo[e.from()];
    					}
    					//Add the vertex in the cycle to a set
    					cycleSet.add(e.from());

    					// Mark the edge to be contracted as in cycle
    					e.setForbidden(true);
    					cycle.push(e);
    				}
    			}
    		}
    	}

        onStack[v] = false;
    }