Submission #415790

#TimeUsernameProblemLanguageResultExecution timeMemory
415790Emin2004Dreaming (IOI13_dreaming)C++14
18 / 100
78 ms17880 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][3]; vector <pii> v[N]; vector <int> vis; void DFS(int node, int r){ used[node] = 1; vis.pb(node); for(pii i : v[node]){ if(!used[i.F]){ used[i.F] = 1; dis[i.F][r] = dis[node][r] + i.S; DFS(i.F, r); } } } 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]}); v[b[i]].pb({a[i], t[i]}); } vector<ll> results; for(int i = 0; i < n; i++){ if(!used[i]) { ll mx = 0, dd = i; dis[dd][0] = 0; DFS(dd, 0); for(int j : vis){ used[j] = 0; if(dis[j][0] >= mx) { mx = dis[j][0]; dd = j; } dis[j][0] = 0; } vis.clear(); dis[dd][0] = 0; DFS(dd, 0); mx = 0; for(int j : vis){ used[j] = 0; if(dis[j][0] >= mx) { mx = dis[j][0]; dd = j; } } vis.clear(); dis[dd][1] = 0; DFS(dd, 1); ll res = mx; for(int j : vis){ res = min(res, max(dis[j][0], dis[j][1])); } vis.clear(); results.pb(res); } } sort(results.begin(), results.end()); int sz = results.size(); ll ans = results[sz - 1]; if(sz >= 2) ans += results[sz - 2] + l; 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...