Submission #76626

#TimeUsernameProblemLanguageResultExecution timeMemory
76626alexpetrescuDreaming (IOI13_dreaming)C++14
100 / 100
179 ms13328 KiB
#include "dreaming.h" #include <vector> #define MAXN 100000 struct myc { int x, y; }; std::vector < myc > g[MAXN]; int ans, best, t[MAXN], opa[MAXN], ops[MAXN], cine[MAXN]; bool viz[MAXN]; void dfs1(int x) { viz[x] = 1; for (auto &y : g[x]) { if (viz[y.x] == 0) { t[y.x] = x; dfs1(y.x); if (opa[y.x] + y.y > opa[x]) { ops[x] = opa[x]; opa[x] = opa[y.x] + y.y; cine[x] = y.x; } else if (opa[y.x] + y.y > ops[x]) ops[x] = opa[y.x] + y.y; } } } void dfs2(int x, int sus) { int cat = std::max(opa[x], sus); if (cat > ans) ans = cat; if (best == -1 || cat < best) best = cat; for (auto &y : g[x]) { if (t[y.x] == x) { if (y.x == cine[x]) dfs2(y.x, y.y + std::max(sus, ops[x])); else dfs2(y.x, y.y + std::max(sus, opa[x])); } } } 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]}); } ans = 0; int max1 = -1, max2 = -1, max3 = -1; for (int i = 0; i < N; i++) { if (viz[i] == 0) { dfs1(i); best = -1; dfs2(i, 0); if (best > max1) { max3 = max2; max2 = max1; max1 = best; } else if (best > max2) { max3 = max2; max2 = best; } else if (best > max3) max3 = best; } } if (max2 != -1) ans = std::max(ans, max1 + max2 + L); if (max3 != -1) ans = std::max(ans, max2 + max3 + 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...