Submission #1041835

#TimeUsernameProblemLanguageResultExecution timeMemory
1041835MMihalevBeads and wires (APIO14_beads)C++14
28 / 100
1043 ms860 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> #pragma GCC optimize("Ofast,no-stack-protector") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #pragma GCC optimize("unroll-loops") #pragma GCC optimize("fast-math") #pragma GCC optimize("vpt") #pragma GCC optimize("rename-registers") #pragma GCC optimize("move-loop-invariants") #pragma GCC optimize("unswitch-loops") #pragma GCC optimize("branch-target-load-optimize2") #pragma GCC optimize("btr-bb-exclusive") using namespace std; const short MAX_N=1e4+1; 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) { int sum=0,cur; for(auto& [v,edge]:g[u]) { if(v==par)continue; dfs(v,u); sum+=max(edge+dp[v][1],dp[v][0]); } for(auto& [v,edge]:g[u]) { if(v==par)continue; cur=max(edge+dp[v][1],dp[v][0]); dp[u][1]=max(dp[u][1],sum-cur+edge+dp[v][0]); } dp[u][0]=sum; } 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; }

Compilation message (stderr)

beads.cpp:22:52: warning: bad option '-fbranch-target-load-optimize2' to pragma 'optimize' [-Wpragmas]
   22 | #pragma GCC optimize("branch-target-load-optimize2")
      |                                                    ^
beads.cpp:23:40: warning: bad option '-fbtr-bb-exclusive' to pragma 'optimize' [-Wpragmas]
   23 | #pragma GCC optimize("btr-bb-exclusive")
      |                                        ^
beads.cpp:30:12: warning: bad option '-fbranch-target-load-optimize2' to attribute 'optimize' [-Wattributes]
   30 | void reset()
      |            ^
beads.cpp:30:12: warning: bad option '-fbtr-bb-exclusive' to attribute 'optimize' [-Wattributes]
beads.cpp:38:27: warning: bad option '-fbranch-target-load-optimize2' to attribute 'optimize' [-Wattributes]
   38 | void dfs(short u,short par)
      |                           ^
beads.cpp:38:27: warning: bad option '-fbtr-bb-exclusive' to attribute 'optimize' [-Wattributes]
beads.cpp: In function 'void dfs(short int, short int)':
beads.cpp:42:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   42 |     for(auto& [v,edge]:g[u])
      |               ^
beads.cpp:50:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   50 |     for(auto& [v,edge]:g[u])
      |               ^
beads.cpp: At global scope:
beads.cpp:59:14: warning: bad option '-fbranch-target-load-optimize2' to attribute 'optimize' [-Wattributes]
   59 | signed main ()
      |              ^
beads.cpp:59:14: warning: bad option '-fbtr-bb-exclusive' to attribute 'optimize' [-Wattributes]
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...