Submission #337685

#TimeUsernameProblemLanguageResultExecution timeMemory
337685BlancaHMDreaming (IOI13_dreaming)C++14
0 / 100
1083 ms8828 KiB
#include <iostream> #include <vector> #include <queue> #include <algorithm> #include "dreaming.h" using namespace std; typedef vector<int> vi; typedef vector<vi> vvi; typedef pair<int, int> pii; typedef vector<pii> vpii; typedef vector<vpii> vvpii; int calcDist(int i, int N, vvpii & G, vi & diam, vector<bool> & visited) { vector<int> dist1, dist2; dist1.assign(N, 1e9); dist1[i] = 0; queue<int> Q; Q.push(i); int u, v, t, maxNode = i; vi CC = {}; while(!Q.empty()) { u = Q.front(); Q.pop(); visited[u] = true; CC.push_back(u); if (dist1[u] > dist1[maxNode]) maxNode = u; for (auto connection: G[u]) { v = connection.first; t = connection.second; if (dist1[v] > dist1[u] + t) { dist1[v] = dist1[u] + t; Q.push(v); } } } dist2.assign(N, 1e9); dist2[maxNode] = 0; Q.push(maxNode); int curDiameter = 0; while(!Q.empty()) { u = Q.front(); curDiameter = max(curDiameter, dist2[u]); Q.pop(); for (auto connection: G[u]) { v = connection.first; t = connection.second; if (dist2[v] > dist2[u] + t) { dist2[v] = dist2[u] + t; Q.push(v); } } } diam.push_back(curDiameter); int ecc = 1e9; for (auto node: CC) ecc = min(ecc, max(dist1[node], dist2[node])); return ecc; } int travelTime(int N, int M, int L, int A[], int B[], int T[]) { vvpii G; G.assign(N, vpii()); for (int i = 0; i < M; i++) { G[A[i]].push_back(make_pair(B[i], T[i])); G[B[i]].push_back(make_pair(A[i], T[i])); } vi ecc, diam; vector<bool> visited(N, false); diam.clear(); ecc.clear(); for (int i = 0; i < N; i++) { if (!visited[i]) ecc.push_back(calcDist(i, N, G, diam, visited)); } sort(ecc.begin(), ecc.end(), greater<int>()); int CC = (int) ecc.size(); int ans = diam[0]; for (int i = 1; i < CC; i++) { ans = max(ans, ecc[0]+ecc[i]+L); } for (int i = 1; i < CC; i++) { for (int j = 2; j < CC; j++) { ans = max(ans, ecc[i]+ecc[j]+2*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...