이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "crocodile.h"
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
int travel_plan(int N, int M, int R[][2], int L[], int K, int P[]) {
vector< vector< pair<int, int> > > g(N);
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]});
}
vector<int> dist1(N, INF), dist2(N, INF);
for (int i = 0; i < K; i++) dist1[P[i]] = dist2[P[i]] = 0;
priority_queue< pair<int, int>, vector< pair<int, int> >, greater< pair<int, int> > > pq;
for (int i = 0; i < K; i++) pq.push({0, P[i]});
while (!pq.empty()) {
int u = pq.top().second, d = pq.top().first; pq.pop();
if (d > dist2[u]) continue;
for (auto& v : g[u]) {
if (dist2[u] + v.second < dist1[v.first]) {
dist2[v.first] = dist1[v.first];
dist1[v.first] = dist2[u] + v.second;
pq.push({dist2[v.first], v.first});
} else if (dist2[u] + v.second < dist2[v.first]) {
dist2[v.first] = dist2[u] + v.second;
pq.push({dist2[v.first], v.first});
}
}
}
return dist2[0];
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |