public ArrayList<DirectedGraphNode> topSort(ArrayList<DirectedGraphNode> graph) {
        // write your code here
        int[] incoming = new int[graph.size()];
        ArrayList<DirectedGraphNode> ans = new ArrayList<DirectedGraphNode>();
        HashMap<Integer, DirectedGraphNode> map = new HashMap<Integer, DirectedGraphNode>();
        for (DirectedGraphNode node : graph) {
            map.put(node.label, node);
            for (DirectedGraphNode n : node.neighbors) {
                incoming[n.label] += 1;
            }
        }
//        return bfs(incoming, ans, map);
        HashSet<Integer> visited = new HashSet<Integer>();
        for (int i = 0; i < graph.size(); ++i) {
            if (incoming[i] == 0 && !visited.contains(i)) {
                dfs(incoming, i, ans, map, visited);
                if (ans.size() == graph.size()) {
                    break;
                }
            }
        }
        return ans;
    }