# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
386583 | Kepha | Crocodile's Underground City (IOI11_crocodile) | C++11 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// IOI 2011 crocodile
#include <bits/stdc++.h>
#define MX 100000
using namespace std;
int N, M, K;
vector<pair<int, int> > edges[MX + 1];
int dist1[MX + 1], dist2[MX + 1];
bool visited[MX + 1];
priority_queue<pair<int, int> > q;
int main() {
// ifstream cin("tmp");
cin >> N >> M >> K;
for (int i = 1; i <= M; i++) {
int a, b, c; cin >> a >> b >> c;
edges[a].push_back({b, c});
edges[b].push_back({a, c});
}
memset(dist1, 0x3f, sizeof(dist1));
memset(dist2, 0x3f, sizeof(dist2));
for (int i = 1; i <= K; i++) {
int x; cin >> x;
dist1[x] = dist2[x] = 0;
q.push({0, x});
}
while (q.size()) {
int node = q.top().second;
q.pop();
if (visited[node]) continue;
visited[node] = true;
for (auto& edge : edges[node]) {
if (dist2[node] + edge.second < dist1[edge.first]) {
dist2[edge.first] = dist1[edge.first];
dist1[edge.first] = dist2[node] + edge.second;
q.push({-dist2[edge.first], edge.first});
}
else if (dist2[node] + edge.second < dist2[edge.first]) {
dist2[edge.first] = dist2[node] + edge.second;
q.push({-dist2[edge.first], edge.first});
}
}
}
cout << dist2[0] << "\n";
return 0;
}