Submission #238568

#TimeUsernameProblemLanguageResultExecution timeMemory
238568arborDreaming (IOI13_dreaming)C++14
18 / 100
62 ms15352 KiB
#include "dreaming.h" #include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int, int>; const int MN = 1e5 + 5; vector<pii> g[MN]; int rt, D, R, dis[MN]; bool vis[MN]; void dfs(int u, int p, int d, bool qu) { vis[u] = true; if (d >= D) D = d, rt = u; if (qu) R = min(R, max(d, dis[u])); else dis[u] = d; for (pii e : g[u]) if (e.first != p) { dfs(e.first, u, d + e.second, qu); } } 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], w = T[i]; g[u].emplace_back(v, w); g[v].emplace_back(u, w); } vector<pii> lens; for (int i = 0; i < N; i++) { if (!vis[i]) { D = 0, R = INT_MAX; dfs(i, -1, 0, 0); dfs(rt, -1, 0, 0); dfs(rt, -1, 0, 1); lens.emplace_back(R, D); } } sort(lens.rbegin(), lens.rend()); if (lens.size() == 1) return lens[0].second; else if (lens.size() == 2) return lens[0].first + L + lens[1].first; else return max(lens[0].first + L + lens[1].first, lens[1].first + 2 * L + lens[2].first); } /* int main() { ios_base::sync_with_stdio(0), cin.tie(0); int a[] = {0,8,2,5,5,1,1,10}; int b[] = {8,2,7,11,1,3,9,6}; int c[] = {4,2,4,3,7,1,5,3}; cout << travelTime(12,8,2,a,b,c) << '\n'; return 0; } */
#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...