Submission #990775

#TimeUsernameProblemLanguageResultExecution timeMemory
990775stdfloatDreaming (IOI13_dreaming)C++17
0 / 100
32 ms13708 KiB
#include <bits/stdc++.h> #include "dreaming.h" using namespace std; #define ff first #define ss second #define pii pair<int, int> int cnt; vector<int> v, u, vis; vector<pii> a; vector<vector<pii>> E; int dfsv(int x, int p = -1) { for (auto [i, w] : E[x]) { if (i != p) v[x] = max(v[x], w + dfsv(i, x)); } return v[x]; } void dfsu(int x) { vis[x] = cnt; for (auto [i, w] : E[x]) { if (!vis[i]) a.push_back({w + v[i], i}); } sort(a.rbegin(), a.rend()); for (auto [i, w] : E[x]) { if (!vis[i]) u[i] = max(u[x], (a[0].ss != i ? a[0].ff : (1 < (int)a.size() ? a[1].ff : 0))) + w; } a.clear(); for (auto [i, w] : E[x]) if (!vis[i]) dfsu(i); } int travelTime(int n, int m, int L, int A[], int B[], int T[]) { E.assign(n, {}); for (int i = 0; i < m; i++) { E[A[i]].push_back({B[i], T[i]}); E[B[i]].push_back({A[i], T[i]}); } v.assign(n, 0); u.assign(n, 0); vis.assign(n, false); for (int i = 0; i < n; i++) { if (!vis[i]) { cnt++; dfsv(i); dfsu(i); } } vector<int> mn(n, INT_MAX); for (int i = 0; i < n; i++) mn[vis[i]] = min(mn[vis[i]], max(v[i], u[i])); sort(mn.begin(), mn.end()); while (mn.back() == INT_MAX) mn.pop_back(); reverse(mn.begin(), mn.end()); if ((int)mn.size() == 1) return mn[0]; else if ((int)mn.size() == 2) return mn[0] + L + mn[1]; return max(mn[0] + L + mn[1], mn[1] + (L << 1) + mn[2]); }
#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...