제출 #1041799

#제출 시각아이디문제언어결과실행 시간메모리
1041799MMihalev구슬과 끈 (APIO14_beads)C++14
28 / 100
1042 ms16116 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 int MAX_N=2e5+4; const int INF=2e9+1e8; int dp[MAX_N][2]; vector<int>pref[MAX_N]; vector<int>suf[MAX_N]; int n; vector<pair<int,int>>g[MAX_N]; void reset() { for(int i=1;i<=n;i++) { pref[i].clear(); suf[i].clear(); dp[i][0]=0; dp[i][1]=-INF; } } void dfs(int u,int par) { int ch=0; for(auto [v,edge]:g[u]) { if(v==par)continue; ch++; dfs(v,u); pref[u].push_back(max(edge+dp[v][1],dp[v][0])); } suf[u]=pref[u]; for(int i=1;i<ch;i++) { pref[u][i]+=pref[u][i-1]; } for(int i=ch-2;i>=0;i--) { suf[u][i]+=suf[u][i+1]; } int i=0; for(auto [v,edge]:g[u]) { if(v==par)continue; dp[u][1]=max(dp[u][1],(i-1>=0 ? pref[u][i-1] : 0)+(dp[v][0]+edge)+(i+1<ch ? suf[u][i+1] : 0)); i++; } if(pref[u].size())dp[u][0]=pref[u].back(); } signed main () { ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); cin>>n; for(int i=1;i<n;i++) { int u,v,c; cin>>u>>v>>c; g[u].push_back({v,c}); g[v].push_back({u,c}); } int ans=0; for(int 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(int, int)':
beads.cpp:36:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   36 |     for(auto [v,edge]:g[u])
      |              ^
beads.cpp:56:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   56 |     for(auto [v,edge]:g[u])
      |              ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...