This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "crocodile.h"
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 100000;
const int INF = 1000000001;
vector<pair<int, int> > graph[MAX_N];
int best[MAX_N][2];
void dijkstra(int N, int K, int P[]) {
priority_queue<pair<int, int> > pq;
for(int i = 0; i < K; ++i) {
best[P[i]][0] = best[P[i]][1] = 0;
pq.push(make_pair(0, P[i]));
}
while(!pq.empty()) {
int nod = pq.top().second;
int cost = -pq.top().first;
pq.pop();
if(best[nod][1] == cost) {
for(auto it: graph[nod]) {
int cost2 = cost + it.second;
int old = best[it.first][1];
if(cost2 < best[it.first][0]) {
best[it.first][1] = best[it.first][0];
best[it.first][0] = cost2;
} else if(cost2 < best[it.first][1])
best[it.first][1] = cost2;
if(best[it.first][1] != old)
pq.push(make_pair(-best[it.first][1], it.first));
}
}
}
}
int travel_plan(int N, int M, int R[][2], int L[], int K, int P[]) {
for(int i = 0; i < M; ++i) {
graph[R[i][0]].push_back(make_pair(R[i][1], L[i]));
graph[R[i][1]].push_back(make_pair(R[i][0], L[i]));
}
for(int i = 0; i < N; ++i) {
best[i][0] = INF;
best[i][1] = INF + 1;
}
dijkstra(N, K, P);
return best[0][1];
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |