fork download
  1. /*
  2. Normal graph routine
  3. */
  4. void dfs(int v, int parent)
  5. {
  6. visited[v] = 1;
  7.  
  8. rep(i, 0, SZ(g[v]))
  9. {
  10. if(!visited[g[v][i]])
  11. dfs(g[v][i], v);
  12. else if(g[v][i] != parent)
  13. {
  14. hasCycle = true;
  15. return;
  16. }
  17. }
  18. }
  19.  
  20. /*
  21.  
  22. calling dfs
  23. */
  24. for(int i=0;i<n;i++)
  25. {
  26. if(!visited[i])
  27. {
  28. dfs(i, -1); //->this line why do people start with -1 even after knowing the fact that -1 can't be there
  29. if(hasCycle)
  30. break;
  31. }
  32. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function 'void dfs(int, int)':
prog.cpp:6:2: error: 'visited' was not declared in this scope
  visited[v] = 1;
  ^
prog.cpp:8:6: error: 'i' was not declared in this scope
  rep(i, 0, SZ(g[v]))
      ^
prog.cpp:8:15: error: 'g' was not declared in this scope
  rep(i, 0, SZ(g[v]))
               ^
prog.cpp:8:19: error: 'SZ' was not declared in this scope
  rep(i, 0, SZ(g[v]))
                   ^
prog.cpp:8:20: error: 'rep' was not declared in this scope
  rep(i, 0, SZ(g[v]))
                    ^
prog.cpp: At global scope:
prog.cpp:24:1: error: expected unqualified-id before 'for'
 for(int i=0;i<n;i++)
 ^
prog.cpp:24:13: error: 'i' does not name a type
 for(int i=0;i<n;i++)
             ^
prog.cpp:24:17: error: 'i' does not name a type
 for(int i=0;i<n;i++)
                 ^
stdout
Standard output is empty