#include "crocodile.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long i64;
const int MAX_N = 1e5 + 5;
vector<vector<pair<int, int>>> g(MAX_N);
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]].emplace_back(R[i][1], L[i]);
g[R[i][1]].emplace_back(R[i][0], L[i]);
}
priority_queue<pair<i64, int>, vector<pair<i64, int>>, greater<pair<i64, int>>> pq;
vector<i64> closest_one(N, 1e18);
for (int i = 0; i < K; i++) {
closest_one[P[i]] = 0;
pq.emplace(closest_one[P[i]], P[i]);
}
while(!pq.empty()) {
auto [w, node] = pq.top();
pq.pop();
if (w != closest_one[node]) {
continue;
}
for (auto [to, cost] : g[node]) {
if (closest_one[to] > closest_one[node] + cost) {
closest_one[to] = closest_one[node] + cost;
pq.emplace(closest_one[to], to);
}
}
}
vector<i64> dist(N, 1e18);
dist[0] = 0;
pq.emplace(dist[0], 0);
while(!pq.empty()) {
auto [w, node] = pq.top();
pq.pop();
if (w != dist[node]) {
continue;
}
pair<i64, int> is_blocked = {1e18, 1e9};
for (auto [to, cost] : g[node]) {
is_blocked = min(is_blocked, {closest_one[to] + cost , to});
}
for (auto [to, cost] : g[node]) {
if (to == is_blocked.second) {
continue;
}
if (dist[to] > dist[node] + cost) {
dist[to] = dist[node] + cost;
pq.emplace(dist[to], to);
}
}
}
i64 best_way = 1e18;
for (int i = 0; i < K; i++) {
best_way = min(best_way, dist[P[i]]);
}
return best_way;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
2688 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
2688 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
2688 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |