Submission #963499

#TimeUsernameProblemLanguageResultExecution timeMemory
963499vivkostovDreaming (IOI13_dreaming)C++14
0 / 100
39 ms12168 KiB
#include<bits/stdc++.h> #include "dreaming.h" using namespace std; void speed() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } struct cell { int to,cost; }; int n,m,l,a1[100005],a2[100005],a3[100005],ma[100005],sma[100005],in[100005],incost[100005],st[100005],used[100005],otg[100005]; vector<cell>v[100005]; void make_ma(int beg) { used[beg]=1; int w; for(int i=0;i<(int)(v[beg].size());i++) { w=v[beg][i].to; if(!used[w]) { make_ma(w); if(ma[beg]<ma[w]+v[beg][i].cost) { sma[beg]=ma[beg]; ma[beg]=ma[w]+v[beg][i].cost; in[beg]=w; incost[beg]=v[beg][i].cost; } else if(sma[beg]<ma[w]+v[beg][i].cost) { sma[beg]=ma[w]+v[beg][i].cost; } } } } int maa; void find_top(int beg,int lead) { if(maa<ma[beg]+sma[beg]) { maa=ma[beg]+sma[beg]; st[lead]=beg; } used[beg]=1; int w; for(int i=0;i<(int)(v[beg].size());i++) { w=v[beg][i].to; if(!used[w]) { find_top(w,lead); } } } void find_otg(int beg,int izm,int lead) { if(beg==0)return; izm=max(izm,sma[beg]); otg[lead]=min(otg[lead],max(max(izm,sma[beg]),ma[beg])); find_otg(in[beg],izm+incost[beg],lead); } void fil(int beg) { int w; used[beg]=1; for(int i=0;i<(int)(v[beg].size());i++) { w=v[beg][i].to; if(!used[w])fil(w); } } int travelTime(int n,int m,int l,int a1[],int a2[],int a3[]) //void read() { //cin>>n>>m>>l; cell h; for(int i=1;i<=m;i++) { //cin>>a1[i]>>a2[i]>>a3[i]; a1[i]++; a2[i]++; h.to=a1[i]; h.cost=a3[i]; v[a2[i]].push_back(h); h.to=a2[i]; v[a1[i]].push_back(h); } for(int i=1;i<=n;i++) { if(!used[i]) { make_ma(i); } } int aa=0; for(int i=1;i<=n;i++) { aa=max(aa,sma[i]+ma[i]); } memset(used,0,sizeof(used)); for(int i=1;i<=n;i++) { if(!used[i]) { find_top(i,i); maa=0; } } memset(used,0,sizeof(used)); for(int i=1;i<=n;i++) { if(!used[i]) { otg[i]=1000000000; find_otg(i,0,i); fil(i); } } sort(otg+1,otg+n+1); if(n-2!=m)aa=max(aa,2*l+otg[n-1]+otg[n-2]); aa=max(aa,l+otg[n-1]+otg[n]); //cout<<aa<<endl; return aa; } /*int main() { speed(); read(); 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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...