#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 (0 <= vis[x] && vis[x] != p && dis[x].ff == LLONG_MAX) dis[x].ff = d;
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 == LLONG_MAX ? -1 : dis[0].ff);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
500 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
516 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
500 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
516 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
604 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
604 KB |
Output is correct |
12 |
Correct |
2 ms |
900 KB |
Output is correct |
13 |
Correct |
3 ms |
1372 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
500 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
516 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
604 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
604 KB |
Output is correct |
12 |
Correct |
2 ms |
900 KB |
Output is correct |
13 |
Correct |
3 ms |
1372 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
254 ms |
59320 KB |
Output is correct |
17 |
Correct |
50 ms |
14928 KB |
Output is correct |
18 |
Correct |
66 ms |
16500 KB |
Output is correct |
19 |
Correct |
369 ms |
68476 KB |
Output is correct |
20 |
Correct |
269 ms |
63964 KB |
Output is correct |
21 |
Correct |
30 ms |
6704 KB |
Output is correct |
22 |
Incorrect |
191 ms |
44884 KB |
Output isn't correct |
23 |
Halted |
0 ms |
0 KB |
- |