이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "crocodile.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n, m;
vector<pair<int, int> > adj[100005];
priority_queue<ll> dist[100005];
int travel_plan(int N, int M, int R[][2], int L[], int K, int P[]){
n = N; m = M;
for (int i = 0; i < m; i++) {
adj[R[i][0]].emplace_back(R[i][1], L[i]);
adj[R[i][1]].emplace_back(R[i][0], L[i]);
}
priority_queue<pair<ll, int> > pq;
for (int i = 0; i < K; i++) {
dist[P[i]].push(0);
dist[P[i]].push(0);
pq.push({ 0, P[i] });
}
while (!pq.empty()) {
ll cost = -pq.top().first;
int now = pq.top().second;
pq.pop();
if (dist[now].top() < cost)continue;
for (auto &e : adj[now]) {
int there = e.first;
int weight = e.second;
if (dist[there].size() < 2) {
dist[there].push(cost + weight);
if (dist[there].size() == 2)
pq.push({ -dist[there].top(),there });
}
else {
if (dist[there].top() > cost + weight) {
dist[there].pop();
dist[there].push(cost + weight);
pq.push({ -dist[there].top(), there });
}
}
}
}
return dist[0].top();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |