Submission #574676

#TimeUsernameProblemLanguageResultExecution timeMemory
574676talant117408Dreaming (IOI13_dreaming)C++17
18 / 100
57 ms16336 KiB
#include "dreaming.h" #include <bits/stdc++.h> //~ #ifndef EVAL //~ #include "grader.cpp" //~ #endif using namespace std; typedef long long ll; typedef pair <int, int> pii; typedef pair <ll, ll> pll; #define pb push_back #define mp make_pair #define lb lower_bound #define ub upper_bound #define all(v) (v).begin(),(v).end() #define sz(v) int((v).size()) #define do_not_disturb ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define endl '\n' const int N = 1e5+7; int used[N]; int n, l, compN, comp[N], furthest[N]; pii compLowest[N], compEnds[N]; vector <pii> graph[N]; void dfs(int v, int p) { used[v] = 1; comp[v] = compN; for (auto to : graph[v]) { if (to.first == p) continue; dfs(to.first, v); } } int df, vf; int distFrom[N][2]; void get_furthest(int v, int p, int dist = 0) { if (dist > df) { df = dist; vf = v; } for (auto to : graph[v]) { if (to.first == p) continue; get_furthest(to.first, v, dist+to.second); } } void calc_dist(int v, int p, int origin, int flag, int d = 0) { if (flag == 0) { distFrom[v][0] = d; } else { distFrom[v][1] = d; } for (auto to : graph[v]) { if (to.first == p) continue; calc_dist(to.first, v, origin, flag, d+to.second); } } int travelTime(int N, int M, int L, int A[], int B[], int T[]) { n = N; for (int i = 0; i < M; i++) { graph[A[i]].pb(mp(B[i], T[i])); graph[B[i]].pb(mp(A[i], T[i])); } for (int i = 1; i <= n; i++) { if (!used[i]) { compLowest[++compN] = mp(2e9, 0); dfs(i, i); df = vf = 0; get_furthest(i, i); compEnds[compN].first = vf; int q = vf; df = vf = 0; get_furthest(q, q); compEnds[compN].second = vf; } } for (int i = 1; i <= n; i++) { used[i] = 0; } for (int i = 1; i <= compN; i++) { calc_dist(compEnds[i].first, compEnds[i].first, compEnds[i].first, 0); calc_dist(compEnds[i].second, compEnds[i].second, compEnds[i].second, 1); } int ans = 0; for (int i = 1; i <= n; i++) { auto c = comp[i]; auto d = max(distFrom[i][0], distFrom[i][1]); ans = max(ans, d); if (compLowest[c].first > d) { compLowest[c].first = d; compLowest[c].second = i; } } vector <int> tmp; for (int i = 1; i <= compN; i++) { tmp.pb(compLowest[i].first); } sort(tmp.rbegin(), tmp.rend()); if (sz(tmp) > 1) { ans = max(ans, tmp[0]+L+tmp[1]); } if (sz(tmp) > 2) { ans = max(ans, tmp[1]+L+L+tmp[2]); } return ans; } //~ int main() { //~ int n, m, l; //~ cin >> n >> m >> l; //~ int x[m], y[m], t[m]; //~ for (int i = 0; i < m; i++) { //~ cin >> x[i] >> y[i] >> t[i]; //~ } //~ cout << travelTime(n, m, l, x, y, t); //~ } /* 12 8 2 0 8 4 8 2 2 2 7 4 5 11 3 5 1 7 1 3 1 1 9 5 10 6 3 */
#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...