| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 | 
|---|---|---|---|---|---|---|---|
| 642558 | Blossomstream | Crocodile's Underground City (IOI11_crocodile) | C++14 | 0 ms | 0 KiB | 
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int n, m, k;
ll d[100000][2];
vector<pair<int, int> > adj[100000];
vector<int> p;
bool visited[100000];
ll MAX_DIST = 1000000001;
ll dijkstra() {
    for(int i = 0; i < n; i++) {
        d[i][0] = MAX_DIST;
        d[i][1] = MAX_DIST;   
    }
    priority_queue<pair<ll, int> > q;
    for(int v: p) {
        d[v][0] = 0;
        d[v][1] = 0;
        q.push(make_pair(0LL, v));
    }
    while(!q.empty()) {
        int v = q.top().second;
        q.pop();
        if(visited[v]) continue;
        visited[v] = true;
        for(auto u: adj[v]) {
            if(visited[u.first]) continue;
            if(d[v][1] + (ll) u.second <= d[u.first][0]) {
                d[u.first][1] = d[u.first][0];
                d[u.first][0] = d[v][1] + (ll) u.second;
            } else {
                d[u.first][1] = min(d[u.first][1], d[v][1] + (ll) u.second);
            }
            q.push(make_pair(-d[u.first][1], u.first));  
        }
    }
    return d[0][1];
}
int main() {
    cin >> n >> m >> k;
    for(int i = 0; i < m; i++) {
        int a, b, l;
        cin >> a >> b >> l;
        adj[a].push_back(make_pair(b, l));
        adj[b].push_back(make_pair(a, l));
    }
    for(int i = 0; i < k; i++) {
        int a;
        cin >> a;
        p.push_back(a);
    }
    cout << dijkstra() << endl;
}
