# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
737874 | Skywk | 악어의 지하 도시 (IOI11_crocodile) | C++17 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
}