writing dfs as a lambda function

Revision en1, by unt311, 2021-04-18 14:51:35

Please share your dfs with lambda function code or improve mine.

        function<void()> dfs = [&](int a, int par, int depth) {
            vis[a] = true;
            if(depth > maxDepth){
                maxDepth = depth;
                farthestNode = a;
            }
            for(auto x: adj[a]){
                if(!vis[x])
                    dfs(x, a, 1 + dep);
            }
        };

I get the following error. error: no match for call to '(std::function<void()>) (long long int&, long long int&, long long int)'|

NOTE: changing a to &a and p to &p in parameter list does not make the error go away.

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English unt311 2021-04-18 14:51:35 681 Initial revision (published)