Submission #43723

#TimeUsernameProblemLanguageResultExecution timeMemory
43723baactreeCrocodile's Underground City (IOI11_crocodile)C++14
89 / 100
1000 ms104360 KiB
#include "crocodile.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; int n, m; vector<pair<int, int> > adj[100005]; priority_queue<ll> dist[100005]; int travel_plan(int N, int M, int R[][2], int L[], int K, int P[]){ n = N; m = M; for (int i = 0; i < m; i++) { adj[R[i][0]].emplace_back(R[i][1], L[i]); adj[R[i][1]].emplace_back(R[i][0], L[i]); } priority_queue<pair<ll, int> > pq; for (int i = 0; i < K; i++) { dist[P[i]].push(0); dist[P[i]].push(0); pq.push({ 0, P[i] }); } while (!pq.empty()) { ll cost = -pq.top().first; int now = pq.top().second; pq.pop(); if (dist[now].top() < cost)continue; for (auto &e : adj[now]) { int there = e.first; int weight = e.second; if (dist[there].size() < 2) { dist[there].push(cost + weight); if (dist[there].size() == 2) pq.push({ -dist[there].top(),there }); } else { if (dist[there].top() > cost + weight) { dist[there].pop(); dist[there].push(cost + weight); pq.push({ -dist[there].top(), there }); } } } } return dist[0].top(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...