Submission #49469

#TimeUsernameProblemLanguageResultExecution timeMemory
49469hamzqq9Beads and wires (APIO14_beads)C++14
0 / 100
4 ms2688 KiB
#include<bits/stdc++.h> #define lf double #define ll long long #define cc pair<char,char> #define ull unsigned ll #define ii pair<int,int> #define li pair<ll,int> #define iii pair<int,ii> #define iiii pair<ii,ii> #define iiii2 pair<int,iii> #define lii pair<ll,ii> #define lolo pair<ll,ll> #define heap priority_queue #define mp make_pair #define st first #define nd second #define pb push_back #define pf push_front #define ppb pop_back #define ppf pop_front #define all(x) x.begin(),x.end() #define len(x) strlen(x) #define sz(x) (int) x.size() #define orta ((bas+son)/2) #define min3(x,y,z) min(min(x,y),z) #define max3(x,y,z) max(max(x,y),z) #define umin(x,y) x=min(x,y) #define umax(x,y) x=max(x,y) #define dbgs(x) cerr<<(#x)<<" --> "<<(x)<<" " #define dbg(x) cerr<<(#x)<<" --> "<<(x)<<endl;getchar() #define MOD 1000000000 #define inf 2000000005 #define N 100005 #define LOG 20 #define magic 100 #define KOK 250 #define EPS 0.0025 #define pw(x) (1<<(x)) #define PI 3.1415926535 using namespace std; int n,x,y,z; int dp[N][2]; vector<ii> v[N]; int pre[N]; void dfs(int node,int ata,int ue) { for(int i=0;i<sz(v[node]);i++) { ii go=v[node][i]; if(go.st==ata) { swap(v[node][i],v[node][sz(v[node])-1]); v[node].ppb(); i--; continue ; } dfs(go.st,node,go.nd); } for(int i=0;i<sz(v[node]);i++) { ii go=v[node][i]; pre[i+1]=pre[i]+dp[go.st][0]; } // make center int mx=-inf; for(int i=0;i<sz(v[node]);i++) { ii go=v[node][i]; for(int j=0;j<2;j++) { umax(dp[node][j],pre[sz(v[node])]-dp[go.st][0]+go.nd+dp[go.st][1]+mx); } umax(mx,go.nd-dp[go.st][0]+dp[go.st][1]); } // not blocked for(int i=0;i<sz(v[node]);i++) { ii go=v[node][i]; umax(dp[node][0],dp[go.st][1]+go.nd+ue+pre[sz(v[node])]-dp[go.st][0]); } // no center for(int j=0;j<2;j++) { umax(dp[node][j],pre[sz(v[node])]); } //printf("node--> %d zero--> %d one--> %d\n",node,dp[node][0],dp[node][1]); } int main() { #if 0 freopen("input.txt","r",stdin); #endif scanf("%d",&n); for(int i=1;i<n;i++) { scanf("%d %d %d",&x,&y,&z); v[x].pb({y,z}); v[y].pb({x,z}); } dfs(1,0,0); printf("%d",dp[1][1]); }

Compilation message (stderr)

beads.cpp: In function 'int main()':
beads.cpp:123:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&n);
  ~~~~~^~~~~~~~~
beads.cpp:127:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d %d",&x,&y,&z);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...