Submission #777874

#TimeUsernameProblemLanguageResultExecution timeMemory
777874zsomborDreaming (IOI13_dreaming)C++17
18 / 100
38 ms13728 KiB
#include <iostream> #include <algorithm> #include <vector> #include "dreaming.h" using namespace std; int mn = 1e9, ans = 0; vector <vector <pair <int, int>>> g(1e5); vector <int> par(1e5, -1); vector <int> down1(1e5, 0); vector <int> down2(1e5, 0); vector <int> up(1e5, 0); vector <int> far(1e5, 0); vector <bool> done(1e5, false); vector <int> MN; void dfs1(int x) { for (auto p : g[x]) { int i = p.first, w = p.second; if (i == par[x]) continue; par[i] = x; dfs1(i); if (down1[i] + w > down1[x]) down1[x] = down1[i] + w; else if (down1[i] + w > down2[x]) down2[x] = down1[i] + w; } } void dfs2(int x) { for (auto p : g[x]) { int i = p.first, w = p.second; if (i == par[x]) continue; up[i] = max(up[x], (down1[x] == down1[i] + w ? down2[x] : down1[x])) + w; dfs2(i); } } void dfs3(int x) { far[x] = max(down1[x], up[x]); mn = min(mn, far[x]); ans = max(ans, far[x]); done[x] = true; for (auto p : g[x]) { int i = p.first; if (i == par[x]) continue; dfs3(i); } } int travelTime(int N, int M, int L, int A[], int B[], int T[]) { for (int i = 0; i < M; i++) { g[A[i]].push_back({ B[i],T[i] }); g[B[i]].push_back({ A[i],T[i] }); } for (int i = 0; i < N; i++) { if (done[i]) continue; dfs1(i); dfs2(i); dfs3(i); MN.push_back(mn); mn = 1e9; } sort(MN.begin(), MN.end()); reverse(MN.begin(), MN.end()); if (MN.size() >= 2) ans = max(ans, MN[0] + MN[1] + L); if (MN.size() >= 3) ans = max(ans, MN[1] + MN[2] + 2 * L); return ans; }
#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...