Submission #940803

#TimeUsernameProblemLanguageResultExecution timeMemory
940803duckindogDreaming (IOI13_dreaming)C++17
0 / 100
1026 ms16328 KiB
#include <bits/stdc++.h> using namespace std; #ifndef LOCAL #include "dreaming.h" #endif const int N = 100'000 + 10; vector<pair<int, int>> ad[N]; int f[N], trace[N]; bool mk[N]; vector<int> node; void dfs(int u, int p = -1) { mk[u] = true; node.push_back(u); trace[u] = p; for (const auto& [v, w] : ad[u]) { if (v == p) continue; f[v] = f[u] + w; dfs(v, u); } } long long wei[N]; int findMid(int u) { int v = u; for (int t = 0; t < 2; ++t) { for (const auto& x : node) f[x] = 0; node.clear(); dfs(u); for (const auto& x : node) if (f[x] > f[v]) v = x; u = v; } vector<int> path; int ret = v; while (v != -1) { if (max(f[v], f[u] - f[v]) < max(f[ret], f[u] - f[ret])) ret = v; v = trace[v]; } wei[ret] = max(f[ret], f[u] - f[ret]); return ret; } int travelTime(int n, int m, int l, int A[],int B[],int T[]) { for (int i = 1; i <= m; ++i) { int u = A[i], v = B[i], w = T[i]; ad[u].push_back({v, w}); ad[v].push_back({u, w}); } memset(trace, -1, sizeof trace); vector<int> nodes; for (int i = 0; i < n; ++i) { if (mk[i]) continue; nodes.push_back(findMid(i)); } sort(nodes.begin(), nodes.end(), [&](const auto& a, const auto& b) { return wei[a] > wei[b]; }); for (const auto& x : nodes) { if (x == nodes[0]) continue; ad[x].push_back({nodes[0], l}); ad[nodes[0]].push_back({x, l}); } memset(f, 0, sizeof f); memset(trace, -1, sizeof trace); findMid(1); return *max_element(f, f + n); } #ifdef LOCAL int n, m, l; int A[N], B[N], T[N]; int32_t main() { cin.tie(0)->sync_with_stdio(0); cin >> n >> m >> l; for (int i = 1; i <= m; ++i) cin >> A[i] >> B[i] >> T[i]; cout << travelTime(n, m, l, A, B, T) << "\n"; } #endif
#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...