Submission #570578

#TimeUsernameProblemLanguageResultExecution timeMemory
570578YouAreMyGalaxyDreaming (IOI13_dreaming)C++17
100 / 100
111 ms18760 KiB
//Make CSP great again //Vengeance #include <bits/stdc++.h> #include "dreaming.h" #define TASK "TESTCODE" #define Log2(x) 31 - __builtin_clz(x) using namespace std; const int N = 1e5; vector<pair<int, int> > Adj[N]; int dp[N], f[N], res; bool visited[N]; void preDFS(int u, int p) { visited[u] = true; for (auto x : Adj[u]) { int v = x.first, w = x.second; if (v == p) { continue; } preDFS(v, u); dp[u] = max(dp[u], dp[v] + w); } } int DFS(int u, int p) { int ret = max(f[u], dp[u]); res = max(res, f[u] + dp[u]); int t[2], id[2]; t[0] = t[1] = id[0] = id[1] = 0; for (auto x : Adj[u]) { int v = x.first, w = x.second; if (v == p) { continue; } f[v] = f[u] + w; for (int i = 1; i >= 0; -- i) { if (t[i] < dp[v] + w) { for (int j = 0; j < i; ++ j) { t[j] = t[j + 1]; id[j] = id[j + 1]; } t[i] = dp[v] + w; id[i] = v; break; } } } for (auto x : Adj[u]) { int v = x.first, w = x.second; if (v == p) { continue; } for (int i = 1; i >= 0; -- i) { if (id[i] != v) { f[v] = max(f[v], t[i] + w); break; } } ret = min(ret, DFS(v, u)); } return ret; } int travelTime(int n, int m, int l, int A[], int B[], int T[]) { for (int i = 0; i < m; ++ i) { int u = A[i], v = B[i]; Adj[u].push_back({v, T[i]}); Adj[v].push_back({u, T[i]}); } int t[3]; t[0] = t[1] = t[2] = 0; int cnt = 0; for (int u = 0; u < n; ++ u) { if (!visited[u]) { ++ cnt; preDFS(u, -1); int x = DFS(u, -1); for (int i = 2; i >= 0; -- i) { if (t[i] < x) { for (int j = 0; j < i; ++ j) { t[j] = t[j + 1]; } t[i] = x; break; } } } } if (cnt >= 2) { res = max(res, t[1] + t[2] + l); } if (cnt >= 3) { res = max(res, t[0] + t[1] + 2 * l); } return res; }
#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...