import java.util.ArrayDeque;
import java.util.Deque;
import java.util.HashMap;
import java.util.Map;
import java.util.Vector;


public class DirectedGraph extends Graph {

	Map<Node<?>, Vector<Node<?>>> graph;
	
	public DirectedGraph(){
		graph = new HashMap<>();
	}
	@Override
	public boolean adjacent(Node<?> from, Node<?> to) {
		if(graph.containsKey(from)){
			if(graph.get(from).contains(to)){
				return true;
			}
		}
		return false;
	}
	@Override
	public Vector<Node<?>> neighbors(Node<?> n) {
		if(graph.containsKey(n)){
			return graph.get(n);
		}
		return null;
	}

	@Override
	public boolean addEdge(Node<?> from, Node<?> to) {
		if(!graph.containsKey(from)){
			if(!graph.containsKey(to)){
				graph.put(to, new Vector<Node<?>>());
			}
			if(!graph.get(from).contains(to)){
				graph.get(from).add(to);
				to.addEdge();
			}
			return true;
		}
		return false;

	}

	@Override
	public void removeEdge(Node<?> from, Node<?> to) {
		if(graph.containsKey(from)){
			if(graph.get(from).contains(to)){
				graph.get(from).remove(to);
				to.decEdge();
				if(to.getEdges()==0){
					graph.remove(to);
				}
			}
		}

	}

	@Override
	public Graph dfs(Graph g, Node<?> head) {
		Graph temp = new DirectedGraph();
		Deque<Node<?>> st = new ArrayDeque<Node<?>>();
		Node<?> current = head;
		do{
			st.push(current);
			for(Node<?> n : g.neighbors(current)){
				temp.addEdge(current.copy(), n.copy());
				st.push(n);
				current.setUsed(true);
				current=st.getFirst();
				if(current.isUsed()){
					//add operations on nodes here
					st.pop();
				}
			}
		}while(!st.isEmpty());
		return temp;
	}

	@Override
	public Graph bfs(Graph g, Node<?> head) {
		Graph temp = new DirectedGraph();
		Deque<Node<?>> st = new ArrayDeque<Node<?>>();
		Node<?> current = head;
		do{
			st.push(current);
			for(Node<?> n : g.neighbors(current)){
				temp.addEdge(current.copy(), n.copy());
				st.push(n);
				current.setUsed(true);
				current=st.getLast();
				if(current.isUsed()){
					//add operations on nodes here
					st.removeLast();
				}
			}
		}while(!st.isEmpty());
		return temp;
	}
	@Override
	public Vector<Node<?>> getNodes() {
		return new Vector<Node<?>>(graph.keySet());
	};

}

@@ -1577,32 +1577,90 @@
 !st.isEmpty());%0A
+%09%09for(Node%3C?%3E n : g.getNodes())%7B%0A%09%09%09n.setUsed(false);%0A%09%09%7D%0A
 %09%09return temp;%0A%09
@@ -2129,16 +2129,74 @@
 pty());%0A
+%09%09for(Node%3C?%3E n : g.getNodes())%7B%0A%09%09%09n.setUsed(false);%0A%09%09%7D%0A
 %09%09return

reset used flag after search