Submission #1013736

#TimeUsernameProblemLanguageResultExecution timeMemory
1013736huutuanDreaming (IOI13_dreaming)C++14
18 / 100
28 ms14672 KiB
#include "dreaming.h" #include <bits/stdc++.h> using namespace std; const int N=1e5+10; vector<pair<int, int>> g[N]; int vis[N], n, m, l, dis[N], par[N]; int mx=-1; void dfs(int u){ vis[u]=1; if (mx==-1 || dis[mx]<dis[u]) mx=u; for (auto &e:g[u]){ int v=e.first, w=e.second; if (v==par[u]) continue; par[v]=u; dis[v]=dis[u]+w; dfs(v); } } pair<int, int> find_diameter(int u){ mx=-1; dis[u]=0; par[u]=-1; dfs(u); u=mx; mx=-1; dis[u]=0; par[u]=-1; dfs(u); int v=mx; pair<int, int> ans; ans.first=dis[v]; ans.second=1e9; while (v!=-1){ ans.second=min(ans.second, max(dis[v], dis[mx]-dis[v])); v=par[v]; } return ans; } int travelTime(int _N, int M, int L, int A[], int B[], int T[]) { n=_N, m=M, l=L; for (int i=0; i<m; ++i) g[A[i]].emplace_back(B[i], T[i]), g[B[i]].emplace_back(A[i], T[i]); vector<pair<int, int>> v; for (int i=0; i<n; ++i) if (!vis[i]){ v.push_back(find_diameter(i)); } if ((int)v.size()==1) return v[0].first; if ((int)v.size()==2) return v[0].second+v[1].second+l; sort(v.begin(), v.end(), [&](pair<int, int> x, pair<int, int> y){ return x.second>y.second; }); return max(v[0].second+v[1].second+l, v[1].second+v[2].second+l+l); }
#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...