### angry_pikachu's blog

By angry_pikachu, history, 19 months ago,

I am getting error

#### 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);


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);

• -21

| Write comment?
 » 19 months ago, # |   +4 Correct it to this 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); 
•  » » 19 months ago, # ^ | ← Rev. 2 →   0 Getting this error prog.cpp: In function ‘void solve()’:prog.cpp:116:16: error: use of deleted function ‘solve()::::~()’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()::::~()’ 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 :(
•  » » » 19 months ago, # ^ |   0 can you share the whole code?I think in the above code ll (long long) is causing the issue as it is getting typecasted to int as a reference argument.
•  » » » » 19 months ago, # ^ |   -8 Yes #include using namespace std; /* DEBUGGING */ void __print(int x) { cerr << x; } void __print(long x) { cerr << x; } void __print(long long x) { cerr << x; } void __print(unsigned x) { cerr << x; } void __print(unsigned long x) { cerr << x; } void __print(unsigned long long x) { cerr << x; } void __print(float x) { cerr << x; } void __print(double x) { cerr << x; } void __print(long double x) { cerr << x; } void __print(char x) { cerr << '\'' << x << '\''; } void __print(const char *x) { cerr << '\"' << x << '\"'; } void __print(const string &x) { cerr << '\"' << x << '\"'; } void __print(bool x) { cerr << (x ? "true" : "false"); } template void __print(const pair &x) { cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}'; } template void __print(const T &x) { int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}"; } void _print() { cerr << "]\n"; } template void _print(T t, V... v) { __print(t); if (sizeof...(v)) cerr << ", "; _print(v...); } #ifndef ONLINE_JUDGE #define deb(x...) \ cerr << "[" << #x << "] = ["; \ _print(x) #else #define deb(x...) #endif /* MACROS */ typedef long long int ll; typedef pair pii; typedef pair pll; typedef vector vi; typedef vector vll; typedef vector vpii; typedef vector vpll; typedef map mii; typedef tuple tup; #define ff first #define ss second #define pb push_back #define IOS \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); struct custom_hash { static uint64_t splitmix64(uint64_t x) { // http://xorshift.di.unimi.it/splitmix64.c x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31); } size_t operator()(uint64_t x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM); } }; // eg - unordered_map safe_map; // for safe hash #define lb lower_bound #define ub upper_bound #define all(x) (x).begin(), (x).end() #define sz(x) (x).size() #define ps(x, y) fixed << setprecision(y) << x #define setbit(x) __builtin_popcountll(x) #define rep(i, a, b) for (int i = a; i < b; ++i) #define repr(i, a, b) for (int i = a; i >= b; --i) /* CONSTANTS */ #define PI 3.141592653589793 const ll MOD = 1e9 + 7; const ll INF = 1000000000; const ll MAX_N = 2e5 + 2; ll add(ll x, ll y) {ll res=x+y; return(res>=MOD?res-MOD:res);} ll mul(ll x, ll y) {ll res=x*y; return(res>=MOD?res%MOD:res);} ll sub(ll x, ll y) {ll res=x-y; return(res<0?res+MOD:res);} ll power(ll a,ll b,ll m=MOD){ ll ans=1; a=a%m; while(b>0) { if(b&1) ans=(1ll*a*ans)%m; b>>=1;a=(1ll*a*a)%m;}return ans;} ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;} ll lcm( ll x, ll y) { return (x*y)/gcd(x,y);} bool isprime(ll n){if(n < 2) return 0; ll i = 2; while(i*i <= n){if(n%i == 0) return 0; i++;} return 1;} void solve() { ll n; cin >> n; vll en(n), fren; rep(i,0,n)cin>>en[i]; fren = en; vll nde[n]; rep(i,0,n-1){ ll x, y; cin>>x>>y; x--,y--; nde[x].pb(y); if(en[x])fren[y]++; if(en[y])fren[x]++; } auto dfs = [&](int i,int x)->void{ fren[i]+=x; for(ll it: nde[i]) dfs(it,fren[i]); }; dfs(0,0); ll q; cin >> q; while(q--){ ll x, t, k; cin>>x>>t>>k; } rep(i,0,n) cout<> t; for(int i = 1; i <= t; i++){ //cout << "Case #<< i << " "; solve(); } } 
•  » » » » » 19 months ago, # ^ |   +11 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.
•  » » » » » » 19 months ago, # ^ |   0 vector nde(n); I have used this, still same error :(
•  » » » » » » » 19 months ago, # ^ |   0 You also have to do the auto&& dfs change that was mentioned in the top level comment.
 » 19 months ago, # | ← Rev. 2 →   +12 Try this function dfs = [&](int i, int x) -> void { fren[i] += x; for (ll it : nde[i]) dfs(it, fren[i]); };