Submission #512409

#TimeUsernameProblemLanguageResultExecution timeMemory
512409ronnithCrocodile's Underground City (IOI11_crocodile)C++14
100 / 100
619 ms63328 KiB
#include "crocodile.h" #include <bits/stdc++.h> using namespace std; const int max_n = (int)1e5; int n, m, k; vector<pair<int, int>> adj[max_n]; int D[max_n]; vector<int> mn2[max_n]; int travel_plan(int N, int M, int R[][2], int L[], int K, int P[]) { n = N; m = M; k = K; for (int i = 0; i < n; i ++) { D[i] = INT_MAX; adj[i].clear(); mn2[i].clear(); } for (int i = 0; i < m; i ++) { adj[R[i][0]].push_back(make_pair(R[i][1], L[i])); adj[R[i][1]].push_back(make_pair(R[i][0], L[i])); } priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq; for (int i = 0; i < k; i ++) { D[P[i]] = 0; pq.push(make_pair(D[P[i]], P[i])); } while ((int)pq.size()) { auto x = pq.top(); pq.pop(); if (x.first != D[x.second]) continue; for (auto& e : adj[x.second]) { mn2[e.first].push_back(D[x.second] + e.second); sort(mn2[e.first].begin(), mn2[e.first].end()); if ((int)mn2[e.first].size() > 2) { mn2[e.first].pop_back(); } if ((int)mn2[e.first].size() == 2 && D[e.first] > mn2[e.first].back()) { D[e.first] = mn2[e.first].back(); pq.push(make_pair(mn2[e.first].back(), e.first)); } } } return D[0]; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...