Submission #1035415

#TimeUsernameProblemLanguageResultExecution timeMemory
1035415andrei_iorgulescuDreaming (IOI13_dreaming)C++14
100 / 100
63 ms16896 KiB
#include "dreaming.h" #include <bits/stdc++.h> using namespace std; bool viz[100005]; vector<pair<int,int>> g[100005]; int t[100005]; int dist[100005]; vector<int> cc; void dfs(int nod) { cc.push_back(nod); viz[nod] = true; for (auto vecin : g[nod]) { if (!viz[vecin.first]) { t[vecin.first] = nod; dist[vecin.first] = dist[nod] + vecin.second; dfs(vecin.first); } } } int travelTime(int N, int M, int L, int A[], int B[], int T[]) { for (int i = 0; i < M; i++) { g[A[i]].push_back({B[i],T[i]}); g[B[i]].push_back({A[i],T[i]}); } vector<int> w; int maxd = 0; for (int i = 0; i < N; i++) { if (!viz[i]) { cc.clear(); dfs(i); int mx = 0,cn = i; for (auto it : cc) { if (dist[it] > mx) mx = dist[it],cn = it; } for (auto it : cc) dist[it] = 0,viz[it] = false,t[it] = 0; cc.clear(); dfs(cn); int rt = cn; mx = 0,cn = rt; for (auto it : cc) { if (dist[it] > mx) mx = dist[it],cn = it; } vector<int> diam; while (cn != rt) diam.push_back(cn),cn = t[cn]; diam.push_back(cn); maxd = max(maxd,mx); int ans = 1e9; for (auto it : diam) ans = min(ans,max(dist[it],mx - dist[it])); w.push_back(ans); } } if (w.size() == 1) return maxd; else { sort(w.begin(),w.end()); int ans = w[w.size() - 1] + w[w.size() - 2] + L; if (w.size() >= 3) ans = max(ans,w[w.size() - 2] + w[w.size() - 3] + L + L); ans = max(ans,maxd); 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...