# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
737874 | Skywk | Crocodile's Underground City (IOI11_crocodile) | C++17 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 1e5;
vector<pair<int, int>> graph[MAXN+1];
int city[MAXN];
priority_queue<long long> best[MAXN+1];
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int N, M, K;
cin>> N>> M>> K;
for(int i=0; i<M; i++){
int u, v, c;
cin>> u>> v>> c;
graph[u].push_back({v, c});
graph[v].push_back({u, c});
}
set<pair<long long, int>> pq;
for(int i=0; i<K; i++){
cin>> city[i];
best[city[i]].push(0);
best[city[i]].push(0);
pq.insert({0, city[i]});
}
while(!pq.empty()){
auto [d, v] = *pq.begin();
pq.erase(pq.begin());
if(best[v].size() < 2 || d != best[v].top()) continue;
for(auto [u, c] : graph[v]){
best[u].push(d + c);
if(best[u].size() > 2){
if(best[u].top() == d + c){
best[u].pop();
continue;
}
pq.erase({u, best[u].top()});
best[u].pop();
}
pq.insert({d + c, u});
}
}
cout<< best[0].top();
return 0;
}