Advertisement
_no0B

Untitled

Nov 29th, 2021
668
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.32 KB | None | 0 0
  1. bool dfs(int node , int par) /// returns 1 if cycle found
  2. {
  3.     bool ans = 0;
  4.     dep[node] = dep[par] + 1;
  5.     vis[node] = 1;
  6.     for(int u:edg[node]){
  7.         if(vis[u] == 0) ans |= dfs(u , node);
  8.         else if(u != par && dep[u] < dep[node]){
  9.             ans = 1;
  10.         }
  11.     }
  12.     return ans;
  13. }
  14. /// O(n + m)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement