Detect cycle in a directed graph | Practice | GeeksforGeeks

someone please check my code i am getting wrong ans, i am applying topological sort in my algorithm.

#include

int timer = 0;
void dfs(int u,vectoradj[],map<int,int>indegree,vectorvisited){
visited[u] = true;
timer++;
indegree[u] = timer;
for(auto it:adj[u]){
if(!visited[it]){
dfs(it,adj,indegree,visited);
}
}
timer = 0;
}

bool isCyclic(int V, vector adj[])
{
// Your code here

map<int,int> indegree;
vector<bool> visited(V,false);
dfs(0,adj,indegree,visited);
for(int i=0;i<V;i++){
    cout << indegree[i] << " ";
}
cout << endl;

string sz= "";
queue<int> q;
for(auto it = indegree.begin(); it!= indegree.end();it++){
    if(it->second == 0){
        q.push(it->first);
    }
}

while(!q.empty()){
    int n = q.front();
    q.pop();
    sz+=to_string(n);
    for(auto it:adj[n]){
        indegree[it]--;
        if(indegree[it] == 0){
            q.push(it);
        }
    }
}
cout << sz << endl;
if(sz.size() > V){
    return true;
}
return false;

}