# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
316732 | 2020-10-27T16:46:40 Z | neki | Dreaming (IOI13_dreaming) | C++14 | 0 ms | 0 KB |
#include <bits/stdc++.h> #include"dreaming.h". #define loop(i, a, b) for(long long i=a;i<b;i++) #define pool(i, a, b) for(long long i=a-1;i>=b;i--) #define fore(i, a) for(auto&& i:a) #define fi first #define se second #define ps(a) push_back(a) #define pb(a) pop_back(a) #define sc scanf #define vc vector #define pa pair<ll, ll> #define ll long long #define lb lower_bound #define ub upper_bound #define all(a) a.begin(), a.end() #define llmax LLONG_MAX/2 #define llmin -LLONG_MAX/2 using namespace std; #define mn 200100 #define pa pair<ll, ll> #define ld long double #define k 450 vc<pa> edg[mn]; vc<ll> ne; ll v1[mn], v2[mn], dp[mn], ans=0; void dfs1(ll u){ v1[u]=1; fore(v, edg[u]) if(!v1[v.fi])dfs1(v.fi), dp[u]=max(dp[u], dp[v.fi]+v.se); } ll dfs2(ll u, ll cur){ v2[u]=1; ans=max(ans, dp[u]); if(cur==-1){ if(edg[u].size()==0) return 0; if(edg[u].size()==1) return min(dp[u], dfs2(edg[u][0].fi, edg[u][0].se)); } ll ret=max(cur, dp[u]); vc<ll> srt;if(cur!=-1) srt.ps(cur); fore(v, edg[u]) if(!v2[v.fi]) srt.ps(dp[v.fi]+v.se); sort(all(srt));ll siz=srt.size(); if(siz>1) ans=max(ans, srt[siz-2]+srt[siz-1]); fore(v, edg[u]) if(!v2[v.fi]){ if(dp[v.fi]+v.se==srt[siz-1]) ret=min(ret, dfs2(v.fi, srt[siz-2]+v.se)); else ret=min(ret, dfs2(v.fi, srt[siz-1]+v.se)); } return ret; } ll travelTime(int n,int m,int L, int a[],int b[],int t[]){ loop(i, 0, m) edg[a[i]].ps(make_pair(b[i], t[i])); loop(i, 0, m) edg[b[i]].ps(make_pair(a[i], t[i])); loop(i, 0, n){ if(!v1[i])dfs1(i); if(!v2[i]) ne.ps((dfs2(i, -1))); } sort(all(ne));ll siz=ne.size(); if(ne.size()==1) return max(ne[0], ans); if(ne.size()==2) return max(ne[1]+ne[2]+L, ans); return max(ans, max(ne[siz-1]+ne[siz-2]+L, ne[siz-3]+ne[siz-2]+2 * L)); }