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