#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;
}
int 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[node] });
}
}
}
return mn_2[0];
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2648 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2648 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2648 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |