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";
}
}