public boolean dfs(HashMap<Integer, HashSet<Integer>> hashMap, boolean[] flags, int node, HashSet<Integer> visited) {
        if (visited.contains(node))
            return false;
        flags[node] = true;
        visited.add(node);
        for (int i : hashMap.get(node)) {
            if (!hashMap.containsKey(i))
                continue;
            if (!dfs(hashMap, flags, i, visited))
                return false;
        }
        visited.remove(node);
        return true;
    }