Submission #984942

#TimeUsernameProblemLanguageResultExecution timeMemory
98494254skyxenonCrocodile's Underground City (IOI11_crocodile)C++17
46 / 100
10 ms9816 KiB
// https://oj.uz/problem/view/IOI11_crocodile /** Needed for linking!!! */ #include "crocodile.h" #include <bits/stdc++.h> using namespace std; #define ll long long #define INF (ll)1e18 vector<map<int, int>> graph; vector<bool> is_exit; vector<bool> visited; ll dfs(int curr) { if (is_exit[curr]) { return 0; } vector<ll> distances; for (auto [nei, weight] : graph[curr]) { if (!visited[nei]) { visited[nei] = true; distances.push_back(weight + dfs(nei)); } } sort(distances.begin(), distances.end()); if (curr == 0) { return distances[1]; } if (distances.size() < 2) { // return INF; throw runtime_error("Got into a cycle!"); } return distances[1]; } int travel_plan(int N, int M, int R[][2], int L[], int K, int P[]) { graph.resize(N); is_exit.resize(N); visited.resize(N); for (int i = 0; i < M; i++) { graph[R[i][0]][R[i][1]] = graph[R[i][1]][R[i][0]] = L[i]; } for (int i = 0; i < K; i++) { is_exit[P[i]] = true; } visited[0] = true; return dfs(0); // try { // } // catch (...) { // vector<int> direct_escapes; // for (auto [nei, dist] : graph[0]) { // if (is_exit[nei]) { // direct_escapes.push_back(dist); // } // } // assert(direct_escapes.size() > 1); // sort(direct_escapes.begin(), direct_escapes.end()); // return direct_escapes[1]; // return *min_element(direct_escapes.begin(), direct_escapes.end()); // } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...