Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bool dfs(int i,bool a[],bool b[],bool c[],vector<int>adj[])
- {
- a[i]=false;
- b[i]=true;
- for(auto it=adj[i].begin();it!=adj[i].end();it++)
- {
- if(b[*it])return true;
- if(a[*it]&&dfs(*it,a,b,c,adj))return true;
- }
- b[i]=false;
- c[i]=true;
- return false;
- }
- bool isCyclic(int V, vector<int> adj[])
- {
- bool a[V]={false};
- bool b[V]={false};
- bool c[V]={false};
- for(int i=0;i<V;i++)a[i]=true;
- for(int i=0;i<V;i++)
- {
- if(a[i])
- {
- if(dfs(i,a,b,c,adj))return true;
- }
- }
- return false;
- }
Add Comment
Please, Sign In to add comment