public ArrayList<DirectedGraphNode> bfs(int[] incoming, ArrayList<DirectedGraphNode> ans, HashMap<Integer, DirectedGraphNode> map) {
        Queue<Integer> queue = new LinkedList<Integer>();
        for (int i = 0; i < incoming.length; ++i) {
            if (incoming[i] == 0)
                queue.offer(i);
        }
        while (!queue.isEmpty()) {
            int node = queue.poll();
            ans.add(map.get(node));
            for (DirectedGraphNode n : map.get(node).neighbors) {
                incoming[n.label] -= 1;
                if (incoming[n.label] == 0)
                    queue.offer(n.label);
            }
        }
        return ans;
    }