Hello Codeforcers!
I'm encountering an issue with a recursive lambda DFS function in my code. Everything was working fine before, but now, after adding this function, I get an error. Can someone help me debug this and find out what's going wrong?
Thanks!
Code :-
int n; cin >> n;
vector<int> g[n];
for(int i=1; i<n; ++i) {
int u, v; cin >> u >> v;
u--; v--;
g[u].push_back(v);
g[v].push_back(u);
}
string s; cin >> s;
vector<int> leaf;
auto dfs = [&](auto &&self, int u, int par) {
for(auto &x : g[u]){
if(x==par) continue;
self(self, x, u);
}
if(g[u].size() == 1) leafs.push_back(u);
};
dfs(dfs,0,-1);
Error :
E:\Programming\cp\Sublime_Files\Hi.cpp: In function 'void solve()':
E:\Programming\cp\Sublime_Files\Hi.cpp:90:16: error: use of deleted function 'solve()::<lambda(auto:1&, ll, ll)>::~<lambda>()'
auto dfs = [&](auto &self, ll u,ll par) {
^
E:\Programming\cp\Sublime_Files\Hi.cpp:90:18: note: 'solve()::<lambda(auto:1&, ll, ll)>::~<lambda>()' is implicitly deleted because the default definition would be ill-formed:
auto dfs = [&](auto &self, ll u,ll par) {
^
[Finished in 283ms]