#include "crocodile.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
vector<pair<int, ll>> g[100005];
ll di[100005][2];
const ll inf = 1e18;
int travel_plan(int N, int M, int R[][2], int L[], int K, int P[]) {
for (int i = 0; i < N; i++) di[i][0] = di[i][1] = inf;
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]});
}
using T = pair<ll, ll>;
priority_queue<T, vector<T>, greater<T>> pq;
for (int i = 0; i < K; i++) {
pq.push({0, P[i]});
di[P[i]][0] = di[P[i]][1] = 0;
}
while (!pq.empty()) {
auto [d, u] = pq.top();
pq.pop();
if (di[u][1] != d) continue;
for (auto& [v, w] : g[u]) {
if (d+w <= di[v][0]) {
di[v][1] = di[v][0];
di[v][0] = d+w;
if (di[v][1] != inf) pq.push({di[v][1], v});
} else if (d+w < di[v][1]) {
di[v][1] = d+w;
pq.push({di[v][1], v});
}
}
}
return di[0][1];
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2648 KB |
Output is correct |
2 |
Correct |
1 ms |
2652 KB |
Output is correct |
3 |
Correct |
1 ms |
2652 KB |
Output is correct |
4 |
Correct |
1 ms |
2908 KB |
Output is correct |
5 |
Correct |
2 ms |
2908 KB |
Output is correct |
6 |
Correct |
1 ms |
2652 KB |
Output is correct |
7 |
Correct |
1 ms |
2908 KB |
Output is correct |
8 |
Correct |
1 ms |
2908 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2648 KB |
Output is correct |
2 |
Correct |
1 ms |
2652 KB |
Output is correct |
3 |
Correct |
1 ms |
2652 KB |
Output is correct |
4 |
Correct |
1 ms |
2908 KB |
Output is correct |
5 |
Correct |
2 ms |
2908 KB |
Output is correct |
6 |
Correct |
1 ms |
2652 KB |
Output is correct |
7 |
Correct |
1 ms |
2908 KB |
Output is correct |
8 |
Correct |
1 ms |
2908 KB |
Output is correct |
9 |
Correct |
2 ms |
3164 KB |
Output is correct |
10 |
Correct |
1 ms |
2652 KB |
Output is correct |
11 |
Correct |
2 ms |
2908 KB |
Output is correct |
12 |
Correct |
5 ms |
3324 KB |
Output is correct |
13 |
Correct |
3 ms |
3420 KB |
Output is correct |
14 |
Correct |
1 ms |
2652 KB |
Output is correct |
15 |
Correct |
2 ms |
2908 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2648 KB |
Output is correct |
2 |
Correct |
1 ms |
2652 KB |
Output is correct |
3 |
Correct |
1 ms |
2652 KB |
Output is correct |
4 |
Correct |
1 ms |
2908 KB |
Output is correct |
5 |
Correct |
2 ms |
2908 KB |
Output is correct |
6 |
Correct |
1 ms |
2652 KB |
Output is correct |
7 |
Correct |
1 ms |
2908 KB |
Output is correct |
8 |
Correct |
1 ms |
2908 KB |
Output is correct |
9 |
Correct |
2 ms |
3164 KB |
Output is correct |
10 |
Correct |
1 ms |
2652 KB |
Output is correct |
11 |
Correct |
2 ms |
2908 KB |
Output is correct |
12 |
Correct |
5 ms |
3324 KB |
Output is correct |
13 |
Correct |
3 ms |
3420 KB |
Output is correct |
14 |
Correct |
1 ms |
2652 KB |
Output is correct |
15 |
Correct |
2 ms |
2908 KB |
Output is correct |
16 |
Correct |
259 ms |
74964 KB |
Output is correct |
17 |
Correct |
44 ms |
16256 KB |
Output is correct |
18 |
Correct |
63 ms |
18788 KB |
Output is correct |
19 |
Correct |
324 ms |
81488 KB |
Output is correct |
20 |
Correct |
169 ms |
61780 KB |
Output is correct |
21 |
Correct |
23 ms |
9296 KB |
Output is correct |
22 |
Incorrect |
194 ms |
57276 KB |
Output isn't correct |
23 |
Halted |
0 ms |
0 KB |
- |