#include <bits/stdc++.h>
#ifndef LOCAL
#include "crocodile.h"
#endif
using namespace std;
const int64_t INF = 1e18;
int travel_plan(int N, int M, int R[][2], int L[], int K, int P[]){
vector<array<int, 2>> g[N];
for(int i = 0; i < M; i++){
int u = R[i][0], v = R[i][1];
g[u].push_back({v, L[i]});
g[v].push_back({u, L[i]});
}
int64_t D[N][2];
int vis[N];
priority_queue< array<int64_t, 2>, vector<array<int64_t, 2>>, greater<array<int64_t, 2>> > pq;
for(int i = 0; i < N; i++){
D[i][0] = D[i][1] = INF;
vis[i] = 0;
}
for(int i = 0; i < K; i++){
int64_t v = P[i];
D[v][0] = D[v][1] = 0;
pq.push({0, v});
}
while(!pq.empty()){
auto [d, node] = pq.top();
pq.pop();
if(vis[node] == 1)
continue;
++vis[node];
for(auto& [v, dx] : g[node]){
int64_t nx = d + int64_t(dx);
if(nx <= D[v][0]){
D[v][1] = D[v][0];
D[v][0] = nx;
if(D[v][1] != INF)
pq.push({D[v][1], v});
}
else if(nx <= D[v][1]){
D[v][1] = nx;
pq.push({D[v][1], v});
}
}
}
return D[0][1];
}
#ifdef LOCAL
int32_t main(){
int N, M, K;
cin >> N >> M >> K;
int R[M][2], L[M], P[K];
for(int i = 0; i < M; i++){
cin >> R[i][0] >> R[i][1] >> L[i];
}
for(int i = 0; i < K; i++){
cin >> P[i];
}
cout << travel_plan(N, M, R, L, K, P) << '\n';
return 0;
}
#endif
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
444 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
444 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
2 ms |
516 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
4 ms |
716 KB |
Output is correct |
13 |
Correct |
4 ms |
768 KB |
Output is correct |
14 |
Correct |
1 ms |
308 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
444 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
2 ms |
516 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
4 ms |
716 KB |
Output is correct |
13 |
Correct |
4 ms |
768 KB |
Output is correct |
14 |
Correct |
1 ms |
308 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
499 ms |
57332 KB |
Output is correct |
17 |
Correct |
83 ms |
14788 KB |
Output is correct |
18 |
Correct |
108 ms |
16284 KB |
Output is correct |
19 |
Correct |
641 ms |
64432 KB |
Output is correct |
20 |
Correct |
316 ms |
47260 KB |
Output is correct |
21 |
Correct |
40 ms |
6340 KB |
Output is correct |
22 |
Correct |
345 ms |
44612 KB |
Output is correct |