Submission #1092630

#TimeUsernameProblemLanguageResultExecution timeMemory
1092630TsotneSVDreaming (IOI13_dreaming)C++17
100 / 100
59 ms27668 KiB
#include "dreaming.h" #include <bits/stdc++.h> using namespace std; /* /\_/\ (= ._.) / > \> */ //#pragma comment(linker, "/stack:200000000") #pragma GCC optimize("Ofast") #pragma GCC optimize ("unroll-loops") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") // codeforces // #define int long long #define fi first #define se second #define pb push_back #define ins insert #define mp make_pair #define send {ios_base::sync_with_stdio(false);} #define help {cin.tie(0);} #define endl '\n' #define sz(x) ((long long) (x).size()) #define all(x) (x).begin(),(x).end() #define print(x) cout<<(x)<<" "; #define printl(x) cout<<(x)<<endl #define dbg(x) cerr<<#x<<" "<<x<<endl typedef long long ll; typedef long double ld; typedef unsigned long long ull; typedef pair<int,int> pii; typedef pair<ll,ll> pll; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<pii> vpi; typedef vector<pll> vpl; const int inf=2e9; const ll INF=1e18; int travelTime(int n, int m, int l, int A[], int B[], int T[]) { vector<pii> g[n]; for(int i=0;i<m;i++) { g[A[i]].pb({B[i],T[i]}); g[B[i]].pb({A[i],T[i]}); } vector<bool> vis(n,0); vector<int> dp1(n),dp2(n),dp3(n),par(n),mn(n,inf); function<void(int,int,int)> dfs1 = [&](int v,int p,int we) -> void { vis[v] = 1; par[v] = (p == -1 ? v : par[p]); dp1[v] = dp2[v] = 0; for(auto [u,w] : g[v]) { if(u == p) continue; dfs1(u,v,w); if(dp1[u] + w > dp1[v]) { dp2[v] = dp1[v]; dp1[v] = dp1[u] + w; }else if(dp1[u] + w > dp2[v]) dp2[v] = dp1[u] + w; } }; function<void(int,int,int)> dfs2 = [&](int v,int p,int we) -> void { if(p != -1) dp3[v] = max(dp3[p],(dp1[p] == dp1[v] + we ? dp2[p] : dp1[p])) + we; else dp3[v] = 0; for(auto [u,w] : g[v]) { if(u == p) continue; dfs2(u,v,w); } }; int ans = 0; for(int i=0;i<n;i++) { if(!vis[i]) { dfs1(i,-1,0); dfs2(i,-1,0); } ans = max(ans,dp1[i] + dp3[i]); } for(int i=0;i<n;i++) mn[par[i]] = min(mn[par[i]],max(dp1[i],dp3[i])); vi v; for(int i=0;i<n;i++) { if(mn[i] != inf) { v.pb(mn[i]); } } sort(all(v)); if(v.size() <= 2) { int sum = l*(sz(v)-1); for(int i : v) sum += i; ans = max(ans,sum); }else { int k = sz(v); ans = max({ans,v[k-1] + l + v[k-2],v[k-2] + 2*l + v[k-3]}); } return ans; } /*int main() { int A[] = {0,8,2,5,5,1,1,10},B[] = {8,2,7,11,1,3,9,6},T[] = {4,2,4,3,7,1,5,3}; printl(travelTime(12,8,2,A,B,T)); 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...