Cycle detection in directed graph

Why am i getting wrong answer ?

bool checkCycleUtil(int node, map<int, bool> &visited, map<int, bool> &inPath) {
visited[node] = true;
inPath[node] = true;

    for(auto nbr:l[node]) {
        if(!visited[nbr]) {
            bool cycleMila = checkCycleUtil(nbr, visited, inPath);
            if(cycleMila) return true;
        }
        else if(inPath[nbr]){
            // back edge
            return true;
        }
    }

    inPath[node] = false;
    return false;
}

void checkCycle() {
    map <int, bool> visited, inPath;
    if(checkCycleUtil(0, visited, inPath)) {
        cout << "Cycle Present";
    }
    else {
        cout << "Cycle Not Present";
    }
}

hello @dar_angel007
call ur checkcycleutil function for each unvisited node.
it might happen that there exist more than one graph (i,e disconected graph) .
so calling for each unvisited node will handle this case

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.