#include <bits/stdc++.h>
#include "crocodile.h"
using namespace std;
#define ff first
#define ss second
#define pii pair<int, int>
using ll = long long;
int travel_plan(int n, int M, int R[][2], int L[], int K, int P[]) {
vector<vector<pii>> E(n);
for (int i = 0; i < M; i++) {
E[R[i][0]].push_back({R[i][1], L[i]});
E[R[i][1]].push_back({R[i][0], L[i]});
}
vector<int> vis(n, -1);
vector<pair<ll, ll>> dis(n, {LLONG_MAX, LLONG_MAX});
priority_queue<pair<ll, pii>> q;
for (int i = 0; i < K; i++) {
vis[P[i]] = -2;
dis[P[i]] = {0, 0};
q.push({0, {P[i], -1}});
}
while (!q.empty()) {
ll d = -q.top().ff;
auto [x, p] = q.top().ss; q.pop();
if (d != dis[x].ff) continue;
if (vis[x] == -1 || vis[x] == p) {
vis[x] = p;
dis[x] = {dis[x].ss, LLONG_MAX};
continue;
}
for (auto [i, w] : E[x]) {
if (d + w < dis[i].ss && vis[i] != x) {
dis[i].ss = d + w;
if (dis[i].ff > dis[i].ss) swap(dis[i].ff, dis[i].ss);
q.push({-d - w, {i, x}});
}
}
}
return dis[0].ff;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
2 ms |
2648 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2556 KB |
Output is correct |
12 |
Correct |
4 ms |
2908 KB |
Output is correct |
13 |
Correct |
3 ms |
3304 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2392 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
2 ms |
2648 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2556 KB |
Output is correct |
12 |
Correct |
4 ms |
2908 KB |
Output is correct |
13 |
Correct |
3 ms |
3304 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2392 KB |
Output is correct |
16 |
Correct |
301 ms |
59332 KB |
Output is correct |
17 |
Correct |
72 ms |
16208 KB |
Output is correct |
18 |
Correct |
79 ms |
18000 KB |
Output is correct |
19 |
Correct |
391 ms |
68544 KB |
Output is correct |
20 |
Correct |
293 ms |
63972 KB |
Output is correct |
21 |
Correct |
28 ms |
6732 KB |
Output is correct |
22 |
Incorrect |
223 ms |
44836 KB |
Output isn't correct |
23 |
Halted |
0 ms |
0 KB |
- |