Submission #415878

#TimeUsernameProblemLanguageResultExecution timeMemory
415878Emin2004Dreaming (IOI13_dreaming)C++14
100 / 100
149 ms20076 KiB
#include "dreaming.h" #include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define pii pair<int, ll> #define F first #define S second const int N = 100005; int used[N]; ll dis[N], dis1[N], dis2[N]; vector <pii> v[N]; vector <int> vis; void DFS(int node){ used[node] = 1; vis.pb(node); for(pii i : v[node]){ if(used[i.F] == 0){ dis[i.F] = dis[node] + i.S; DFS(i.F); } } } void DFS1(int node){ used[node] = 2; for(pii i : v[node]){ if(used[i.F] != 2){ dis1[i.F] = dis1[node] + i.S; DFS1(i.F); } } } void DFS2(int node){ used[node] = 3; for(pii i : v[node]){ if(used[i.F] != 3){ dis2[i.F] = dis2[node] + i.S; DFS2(i.F); } } } int travelTime(int n, int m, int l, int a[], int b[], int t[]) { if(n == 1) return 0; for(int i = 0; i < m; i++){ v[a[i]].pb({b[i], t[i] * 1ll}); v[b[i]].pb({a[i], t[i] * 1ll}); } vector<ll> results; ll ans = 0; for(int i = 0; i < n; i++){ if(!used[i]) { vis.clear(); ll mx = 0, dd = i; DFS(dd); for(int j : vis){ if(dis[j] >= mx) { mx = dis[j]; dd = j; } dis[j] = 0; } DFS1(dd); mx = 0; for(int j : vis){ if(dis1[j] >= mx) { mx = dis1[j]; dd = j; } } dis[dd] = 0; DFS2(dd); ll res = mx; for(int j : vis){ res = min(res, max(dis1[j], dis2[j])); } results.pb(res); ans = max(ans, mx); } } sort(results.begin(), results.end()); int sz = results.size(); ans = max(ans, results[sz - 1]); if(sz >= 2) ans = max(ans, results[sz - 2] + l + results[sz - 1]); if(sz >= 3) ans = max(ans, results[sz - 2] + results[sz - 3] + l + 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...