Submission #764010

#TimeUsernameProblemLanguageResultExecution timeMemory
764010NothingXDDreaming (IOI13_dreaming)C++17
100 / 100
56 ms14540 KiB
#include "dreaming.h" #include<bits/stdc++.h> using namespace std; typedef long long ll; typedef double ld; typedef pair<int,int> pii; typedef pair<ll,ll> pll; typedef complex<ld> point; void debug_out(){cerr << endl;} template<typename Head, typename... Tail> void debug_out(Head H, Tail... T){ cout << H << ' '; debug_out(T...); } #define debug(...) cerr << "(" << #__VA_ARGS__ << "): ", debug_out(__VA_ARGS__) #define F first #define S second #define all(x) x.begin(), x.end() #define MP(x, y) make_pair(x, y) const int maxn = 1e5 + 10; const int inf = 1e9; int n, m, l, h[2][maxn]; vector<pii> g[maxn]; vector<int> going, res; bool vis[maxn]; void dfs(int v, int *h, int p = -1){ vis[v] = true; going.push_back(v); for (auto [u, w]: g[v]){ if (u != p){ h[u] = h[v] + w; dfs(u, h, v); } } } 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]].push_back({B[i], T[i]}); g[B[i]].push_back({A[i], T[i]}); } int ans = 0; for (int i = 0; i < n; i++){ if (!vis[i]){ going.clear(); dfs(i, h[0]); int q1 = i; for (auto x: going){ if (h[0][x] > h[0][q1]) q1 = x; } going.clear(); dfs(q1, h[1]); int q2 = i; for (auto x: going){ if (h[1][x] > h[1][q2]) q2 = x; } ans = max(ans, h[1][q2]); going.clear(); h[0][q2] = 0; dfs(q2, h[0]); int tmp = inf; for (auto x: going){ tmp = min(tmp, max(h[0][x], h[1][x])); } res.push_back(tmp); } } sort(all(res), greater<int>()); if (res.size() >= 2) ans = max(ans, res[0] + res[1] + l); if (res.size() >= 3) ans = max(ans, res[1] + res[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...