Submission #544299

#TimeUsernameProblemLanguageResultExecution timeMemory
544299JomnoiDreaming (IOI13_dreaming)C++17
0 / 100
1091 ms17740 KiB
#include <bits/stdc++.h> #include "dreaming.h" using namespace std; const int MAX = 1e5 + 10; vector <pair <int, int>> adj[MAX]; pair <int, int> ma[MAX][2]; bool visited[MAX]; template <typename T> void upd(T *ma, T x) { if(ma[0] < x) { swap(ma[0], x); } if(ma[1] < x) { swap(ma[1], x); } } void dfs(int u, int p) { for(auto [v, w] : adj[u]) { if(v == p) { continue; } dfs(v, u); upd(ma[u], make_pair(ma[v][0].first + w, v)); } } int dfs2(int u, int p, int pw) { int res = ma[u][0].first + pw; for(auto [v, w] : adj[u]) { if(v == p) { continue; } int nw = pw + w; if(ma[u][0].second == v) { nw += ma[u][1].first; } else { nw += ma[u][0].first; } res = min(res, dfs2(v, u, nw)); } return res; } int travelTime(int N, int M, int L, int A[], int B[], int T[]) { for(int i = 0; i < M; i++) { A[i]++, B[i]++; adj[A[i]].emplace_back(B[i], T[i]); adj[B[i]].emplace_back(A[i], T[i]); } for(int i = 1; i <= N; i++) { ma[i][0] = make_pair(0, -1); ma[i][1] = make_pair(0, -1); } for(int i = 1; i <= N; i++) { if(ma[i][0].second == -1) { dfs(i, -1); } } int max_dist[2] = {-1, -1}; for(int i = 1; i <= N; i++) { if(visited[i] == false) { visited[i] = true; upd(max_dist, dfs2(i, -1, 0)); } } if(max_dist[1] == -1) { return max_dist[0] + L; } return max_dist[0] + max_dist[1] + 2 * L; }
#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...