Submission #415772

#TimeUsernameProblemLanguageResultExecution timeMemory
415772Emin2004Dreaming (IOI13_dreaming)C++14
0 / 100
142 ms15932 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][2]; 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[]) { // return n; 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); for(int j : vis){ mx = min(mx, max(dis[j][0], dis[j][1])); } vis.clear(); results.pb(mx); } } sort(results.begin(), results.end()); int sz = results.size(); ll ans = results[sz - 1]; if(sz >= 2) ans += results[sz - 2] + l; else{ while(6 > 0){ vis.pb(12); } } 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...