fork download
  1. set<int> cat; // store info about the cat
  2. vector<vector<int>>v; // graph
  3. int ans = 0; // final answer
  4. vector<int>visited; // keep track of visited nodes , have size (n)
  5. void dfs(int start /*current node */,int anc /* ancestor */ ,int m /*total cats*/ ,int counter =0 /* cats on path*/){
  6. if(cat.find(start)!=cat.end()){
  7. counter++;
  8. }else{
  9. counter=0;
  10. }
  11. if(counter==m+1){ // condition failed
  12. return;
  13. }
  14. bool o=true; // will be true if leaf node
  15. for(auto itr:v[start]){
  16. if(itr!=anc){
  17. o=false;
  18. dfs(itr,start , m , counter);
  19. }
  20. }
  21. if(o){
  22. ans++;
  23. }
  24. return ;
  25. }
  26.  
  27.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:1:1: error: no template named 'set'
set<int> cat; // store info about the cat 
^
prog.cpp:2:1: error: no template named 'vector'
vector<vector<int>>v; // graph
^
prog.cpp:2:8: error: use of undeclared identifier 'vector'
vector<vector<int>>v; // graph
       ^
prog.cpp:2:18: error: expected '(' for function-style cast or type construction
vector<vector<int>>v; // graph
              ~~~^
prog.cpp:4:1: error: no template named 'vector'
vector<int>visited; // keep track of visited nodes , have size (n)
^
prog.cpp:15:18: error: use of undeclared identifier 'v'
    for(auto itr:v[start]){
                 ^
6 errors generated.
stdout
Standard output is empty