#include "crocodile.h"
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
int travel_plan(int N, int M, int R[][2], int L[], int K, int P[]) {
vector< vector< pair<int, int> > > g(N);
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]});
}
vector<int> dist1(N, INF), dist2(N, INF);
for (int i = 0; i < K; i++) dist1[P[i]] = dist2[P[i]] = 0;
priority_queue< pair<int, int>, vector< pair<int, int> >, greater< pair<int, int> > > pq;
for (int i = 0; i < K; i++) pq.push({0, P[i]});
while (!pq.empty()) {
int u = pq.top().second, d = pq.top().first; pq.pop();
if (d > dist2[u]) continue;
for (auto& v : g[u]) {
if (dist2[u] + v.second < dist1[v.first]) {
dist2[v.first] = dist1[v.first];
dist1[v.first] = dist2[u] + v.second;
pq.push({dist2[v.first], v.first});
} else if (dist2[u] + v.second < dist2[v.first]) {
dist2[v.first] = dist2[u] + v.second;
pq.push({dist2[v.first], v.first});
}
}
}
return dist2[0];
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
492 KB |
Output is correct |
5 |
Correct |
1 ms |
492 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
492 KB |
Output is correct |
8 |
Correct |
1 ms |
492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
492 KB |
Output is correct |
5 |
Correct |
1 ms |
492 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
492 KB |
Output is correct |
8 |
Correct |
1 ms |
492 KB |
Output is correct |
9 |
Correct |
4 ms |
620 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
492 KB |
Output is correct |
12 |
Correct |
4 ms |
876 KB |
Output is correct |
13 |
Correct |
4 ms |
876 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
492 KB |
Output is correct |
5 |
Correct |
1 ms |
492 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
492 KB |
Output is correct |
8 |
Correct |
1 ms |
492 KB |
Output is correct |
9 |
Correct |
4 ms |
620 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
492 KB |
Output is correct |
12 |
Correct |
4 ms |
876 KB |
Output is correct |
13 |
Correct |
4 ms |
876 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
492 KB |
Output is correct |
16 |
Correct |
502 ms |
56928 KB |
Output is correct |
17 |
Correct |
104 ms |
14952 KB |
Output is correct |
18 |
Correct |
134 ms |
16360 KB |
Output is correct |
19 |
Correct |
626 ms |
63332 KB |
Output is correct |
20 |
Correct |
316 ms |
47340 KB |
Output is correct |
21 |
Correct |
46 ms |
6508 KB |
Output is correct |
22 |
Incorrect |
343 ms |
44868 KB |
Output isn't correct |