# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
737874 | 2023-05-07T21:47:16 Z | Skywk | 악어의 지하 도시 (IOI11_crocodile) | C++17 | 0 ms | 0 KB |
#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; }