# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
372849 | 2021-03-02T02:16:08 Z | ntabc05101 | 악어의 지하 도시 (IOI11_crocodile) | C++14 | 0 ms | 0 KB |
#include<bits/stdc++.h> using namespace std; #define f first #define s second const int64_t inf = 1e17; const int max_n = 100000; const int max_m = 100000; struct Edge { int x, y, w; }; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, m, k; cin >> n >> m >> k; Edge edges[m]; for (int i = 0; i < m; i++) { cin >> edges[i].x >> edges[i].y; //edges[i].x--; //edges[i].y--; } for (int i = 0; i < m; i++) { cin >> edges[i].w; } vector< pair<int, int> > adjList[n]; for (int i = 0; i < m; i++) { adjList[edges[i].x].push_back({edges[i].y, edges[i].w}); adjList[edges[i].y].push_back({edges[i].x, edges[i].w}); } priority_queue< pair<int64_t, int> > pq; int64_t dist[n]; vector<int64_t> distList[n]; for (int i = 0; i < n; i++) { dist[i] = inf; } while (k--) { int u; cin >> u; //u--; distList[u].push_back(0); pq.push({-0, u}); } while (!pq.empty()) { int64_t cdist = -pq.top().first; int cvertex = pq.top().second; //cout << cdist << " " << cvertex << "\n"; pq.pop(); if (distList[cvertex].size() > 1) continue; distList[cvertex].push_back(cdist); if (distList[cvertex].size() == 2) { for (auto& to: adjList[cvertex]) { pq.push({-(cdist+to.s), to.f}); } } } cout << distList[0][1] << "\n"; return 0; } /* 5 4 3 0 1 0 2 3 2 2 4 2 3 1 4 1 3 4 */ /* 5 7 2 0 2 0 3 3 2 2 1 0 1 0 4 3 4 4 3 2 10 100 7 9 1 3 */