# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1087972 | T0p_ | 악어의 지하 도시 (IOI11_crocodile) | C++14 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "crocodile.h"
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 100000 + 5;
struct Dijkstra {
int node;
long long weight;
bool operator < (const Dijkstra & o) const {
return weight > o.weight;
}
};
long long mn_1[MAX_N], mn_2[MAX_N];
vector<pair<int, long long>> g[MAX_N];
bool update(int u, long long v) {
if (v < mn_1[u]) {
mn_2[u] = mn_1[u];
mn_1[u] = v;
return true;
}
else if (v < mn_2[u]) {
mn_2[u] = v;
return true;
}
return false;
}
long long travel_plan(int N, int M, int R[][2], int L[], int K, int P[]) {
for (int i=0 ; i<M ; i++) {
g[R[i][0]].push_back({ R[i][1], L[i] });
g[R[i][1]].push_back({ R[i][0], L[i] });
}
for (int i=0 ; i<N ; i++) {
mn_1[i] = mn_2[i] = 2e9;
}
priority_queue<Dijkstra> dijkstra;
for (int i=0 ; i<K ; i++) {
mn_1[P[i]] = mn_2[P[i]] = 0;
dijkstra.push({ P[i], 0 });
}
while (!dijkstra.empty()) {
int node = dijkstra.top().node;
long long weight = dijkstra.top().weight;
dijkstra.pop();
if (weight != mn_2[node]) continue;
for (pair<int, long long> edge : g[node]) {
if (update(edge.first, weight + edge.second) && edge.first != 0) {
dijkstra.push({ edge.first, mn_2[edge.first] });
}
}
}
return mn_2[0];
}