I am getting error
prog.cpp: In lambda function:
prog.cpp:118:28: error: use of ‘dfs’ before deduction of ‘auto’
118 | for(ll it: nde[i]) dfs(it,fren[i]);
In this code , ll means long long, nde[i] is a vector of int
auto dfs = [&](int i,int x)->void{
fren[i]+=x;
for(ll it: nde[i]) dfs(it,fren[i]);
};
dfs(0,0);
Writing a blog in codeforces for first time
C++ 17 online compiler
Worked using
function<void(int, int)> dfs = [&](int i, int x) -> void {
fren[i] += x;
for (ll it : nde[i])
dfs(it, fren[i]);
};
Also by changing vector<int> nde[n]
to vector<vector<int>> nde(n)
and by using the function
auto dfs = [&](int i,int x, auto &&dfs)->void{
fren[i]+=x;
for(ll it: nde[i]) dfs(it,fren[i], dfs);
};
dfs(0,0,dfs);
Correct it to this
Getting this error
prog.cpp: In function ‘void solve()’:
prog.cpp:116:16: error: use of deleted function ‘solve()::<lambda(int, int, auto:22&&)>::~()’
116 | auto dfs = [&](int i,int x, auto &&dfs)->void{
117 | fren[i]+=x;
118 | for(ll it: nde[i]) dfs(it,fren[i], dfs);
119 | };
prog.cpp:116:18: note: ‘solve()::<lambda(int, int, auto:22&&)>::~()’ is implicitly deleted because the default definition would be ill-formed:
116 | auto dfs = [&](int i,int x, auto &&dfs)->void{
Have to edit the comment due to multi line issue :(
can you share the whole code?
I think in the above code
ll
(long long) is causing the issue as it is getting typecasted toint
as a reference argument.Yes
Try removing the VLA. A lot of people I know face this same error because they use VLAs. More precisely, do something about the
vll nde[n];
and convert it to a vector of vectors. VLAs are gcc extensions and are discouraged, and are not legal C++ at all.vector<vll> nde(n);
I have used this, still same error :(
You also have to do the
auto&& dfs
change that was mentioned in the top level comment.Try this