Submission #389165

#TimeUsernameProblemLanguageResultExecution timeMemory
389165mosiashvililukaBeads and wires (APIO14_beads)C++14
28 / 100
1080 ms15180 KiB
#include<bits/stdc++.h> using namespace std; const long long N=1000000000000000000LL; long long a,b,c,d,e,i,j,ii,jj,zx,xc,pas,dp[200009],dp2[200009]; pair <long long, long long> msh[200009]; vector <pair <long long, long long> > v[200009]; multiset <long long> s[200009]; void dfsst(long long q, long long w){ long long qw=-N; for(vector <pair <long long, long long> >::iterator it=v[q].begin(); it!=v[q].end(); it++){ if((*it).first==w) continue; msh[(*it).first]=make_pair(q,(*it).second); dfsst((*it).first,q); dp[q]+=max(dp[(*it).first],dp2[(*it).first]); if(qw<(*it).second+dp[(*it).first]-max(dp[(*it).first],dp2[(*it).first])) qw=(*it).second+dp[(*it).first]-max(dp[(*it).first],dp2[(*it).first]); } if(qw!=-N){ dp2[q]=msh[q].second+dp[q]+qw; }else{ dp2[q]=-N; } } int main(){ ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0); cin>>a; for(i=1; i<a; i++){ cin>>c>>d>>e; v[c].push_back(make_pair(d,e)); v[d].push_back(make_pair(c,e)); } for(i=1; i<=a; i++){ for(j=0; j<=a+1; j++){ dp[j]=dp2[j]=0; } dfsst(i,0); pas=max(pas,dp[i]); } cout<<pas; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...