#include "crocodile.h"
#include <bits/stdc++.h>
using namespace std;
inline namespace
{
} // namespace
int travel_plan(int N, int M, int R[][2], int L[], int K, int P[])
{
vector<vector<pair<int, int>>> adj(N);
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]);
vector<array<int, 2>> dist(N, {INT_MAX, INT_MAX});
priority_queue<pair<int, int>> pq;
for (int i = 0; i < K; i++)
dist[P[i]] = {0, 0}, pq.emplace(-dist[P[i]][0], P[i]);
for (vector<bool> done(N, 0); !done[0];)
{
auto [d, u] = pq.top();
pq.pop();
if (done[u])
continue;
done[u] = 1;
for (auto [v, w] : adj[u])
{
int cost = w - d;
if (cost < dist[v][0])
dist[v][1] = dist[v][0],
dist[v][0] = cost;
else if (cost < dist[v][1])
dist[v][1] = cost;
else
continue;
pq.emplace(-dist[v][1], v);
}
}
return dist[0][1];
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
3 ms |
576 KB |
Output is correct |
10 |
Correct |
1 ms |
312 KB |
Output is correct |
11 |
Correct |
2 ms |
340 KB |
Output is correct |
12 |
Correct |
4 ms |
724 KB |
Output is correct |
13 |
Correct |
3 ms |
852 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
3 ms |
576 KB |
Output is correct |
10 |
Correct |
1 ms |
312 KB |
Output is correct |
11 |
Correct |
2 ms |
340 KB |
Output is correct |
12 |
Correct |
4 ms |
724 KB |
Output is correct |
13 |
Correct |
3 ms |
852 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
389 ms |
56836 KB |
Output is correct |
17 |
Correct |
87 ms |
14852 KB |
Output is correct |
18 |
Correct |
95 ms |
15812 KB |
Output is correct |
19 |
Correct |
468 ms |
63092 KB |
Output is correct |
20 |
Correct |
268 ms |
47232 KB |
Output is correct |
21 |
Correct |
37 ms |
6400 KB |
Output is correct |
22 |
Correct |
305 ms |
44604 KB |
Output is correct |