제출 #1041826

#제출 시각아이디문제언어결과실행 시간메모리
1041826MMihalev구슬과 끈 (APIO14_beads)C++14
컴파일 에러
0 ms0 KiB
#include<iostream> #include<algorithm> #include<iomanip> #include<cmath> #include<cstring> #include<vector> #include<queue> #include<stack> #include<tuple> #include<set> #include<map> #include<random> #include<chrono> using namespace std; const short MAX_N=1e4+4; const int INF=2e9+1e8; int dp[MAX_N][2]; short n; vector<pair<short,short>>g[MAX_N]; void reset() { for(short i=1;i<=n;i++) { dp[i][0]=0; dp[i][1]=-INF; } } void dfs(short u,short par) { short ch=0,i; vector<int>suf; int pref=0; for(auto [v,edge]:g[u]) { if(v==par)continue; ch++; dfs(v,u); suf.push_back(max(edge+dp[v][1],dp[v][0])); } for(i=ch-2;i>=0;i--) { suf[i]+=suf[i+1]; } i=0; for(auto [v,edge]:g[u]) { if(v==par)continue; dp[u][1]=max(dp[u][1],(i-1>=0 ? pref[i-1] : 0)+(dp[v][0]+edge)+(i+1<ch ? suf[i+1] : 0)); pref+=max(edge+dp[v][1],dp[v][0]); i++; } dp[u][0]=pref; //vector<int>().swap(pref);vector<int>().swap(suf); } signed main () { ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); cin>>n; for(short i=1;i<n;i++) { short u,v,c; cin>>u>>v>>c; g[u].push_back({v,c}); g[v].push_back({u,c}); } int ans=0; for(short i=1;i<=n;i++) { reset(); dfs(i,0); ans=max(ans,dp[i][0]); } cout<<ans<<"\n"; return 0; }

컴파일 시 표준 에러 (stderr) 메시지

beads.cpp: In function 'void dfs(short int, short int)':
beads.cpp:34:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   34 |     for(auto [v,edge]:g[u])
      |              ^
beads.cpp:49:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   49 |     for(auto [v,edge]:g[u])
      |              ^
beads.cpp:53:45: error: invalid types 'int[int]' for array subscript
   53 |         dp[u][1]=max(dp[u][1],(i-1>=0 ? pref[i-1] : 0)+(dp[v][0]+edge)+(i+1<ch ? suf[i+1] : 0));
      |                                             ^