#include "crocodile.h"
#include <iostream>
#include <vector>
#include <array>
#include <queue>
#define ll long long
using namespace std;
vector <array<ll, 2> > adj[100000];
priority_queue <array<ll, 2>, vector<array<ll, 2>>, greater<array<ll,2>>> pq;
ll dist[100000], in[100000], MN[2][100000];
int travel_plan(int N, int M, int R[][2], int L[], int K, int P[])
{
for (int i=0; i<N; ++i) dist[i] = MN[0][i] = MN[1][i] = 1e18;
for (int i=0; i<M; ++i) {
adj[R[i][0]].push_back({R[i][1], L[i]});
adj[R[i][1]].push_back({R[i][0], L[i]});
}
for (int i=0; i<K; ++i) {
dist[P[i]] = 0;
pq.push({0, P[i]});
}
while (!pq.empty()) {
auto [w, u] = pq.top();
pq.pop();
if (dist[u] != w) continue;
for (auto [v, x] : adj[u]) {
if (dist[v] > dist[u]+x) {
++in[v];
if (in[v] == 1) MN[0][v] = dist[u]+x;
else if (in[v] == 2) {
MN[1][v] = max(MN[0][v], dist[u]+x);
MN[0][v] = min(MN[0][v], dist[u]+x);
dist[v] = MN[1][v];
pq.push({dist[v], v});
}
else {
if (MN[0][v] > dist[u]+x) {
MN[1][v] = MN[0][v];
MN[0][v] = dist[u]+x;
dist[v] = MN[1][v];
pq.push({dist[v], v});
}
else if (MN[1][v] > dist[u]+x) {
MN[1][v] = dist[u]+x;
dist[v] = MN[1][v];
pq.push({dist[v], v});
}
}
}
}
}
return dist[0];
}
Compilation message
crocodile.cpp: In function 'int travel_plan(int, int, int (*)[2], int*, int, int*)':
crocodile.cpp:26:10: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
26 | auto [w, u] = pq.top();
| ^
crocodile.cpp:29:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
29 | for (auto [v, x] : adj[u]) {
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2644 KB |
Output is correct |
2 |
Correct |
1 ms |
2644 KB |
Output is correct |
3 |
Correct |
2 ms |
2644 KB |
Output is correct |
4 |
Correct |
2 ms |
2804 KB |
Output is correct |
5 |
Correct |
2 ms |
2772 KB |
Output is correct |
6 |
Correct |
2 ms |
2772 KB |
Output is correct |
7 |
Correct |
2 ms |
2800 KB |
Output is correct |
8 |
Correct |
2 ms |
2772 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2644 KB |
Output is correct |
2 |
Correct |
1 ms |
2644 KB |
Output is correct |
3 |
Correct |
2 ms |
2644 KB |
Output is correct |
4 |
Correct |
2 ms |
2804 KB |
Output is correct |
5 |
Correct |
2 ms |
2772 KB |
Output is correct |
6 |
Correct |
2 ms |
2772 KB |
Output is correct |
7 |
Correct |
2 ms |
2800 KB |
Output is correct |
8 |
Correct |
2 ms |
2772 KB |
Output is correct |
9 |
Correct |
3 ms |
3124 KB |
Output is correct |
10 |
Correct |
2 ms |
2644 KB |
Output is correct |
11 |
Correct |
2 ms |
2772 KB |
Output is correct |
12 |
Correct |
5 ms |
3412 KB |
Output is correct |
13 |
Correct |
5 ms |
3412 KB |
Output is correct |
14 |
Correct |
2 ms |
2644 KB |
Output is correct |
15 |
Correct |
2 ms |
2828 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2644 KB |
Output is correct |
2 |
Correct |
1 ms |
2644 KB |
Output is correct |
3 |
Correct |
2 ms |
2644 KB |
Output is correct |
4 |
Correct |
2 ms |
2804 KB |
Output is correct |
5 |
Correct |
2 ms |
2772 KB |
Output is correct |
6 |
Correct |
2 ms |
2772 KB |
Output is correct |
7 |
Correct |
2 ms |
2800 KB |
Output is correct |
8 |
Correct |
2 ms |
2772 KB |
Output is correct |
9 |
Correct |
3 ms |
3124 KB |
Output is correct |
10 |
Correct |
2 ms |
2644 KB |
Output is correct |
11 |
Correct |
2 ms |
2772 KB |
Output is correct |
12 |
Correct |
5 ms |
3412 KB |
Output is correct |
13 |
Correct |
5 ms |
3412 KB |
Output is correct |
14 |
Correct |
2 ms |
2644 KB |
Output is correct |
15 |
Correct |
2 ms |
2828 KB |
Output is correct |
16 |
Correct |
419 ms |
83684 KB |
Output is correct |
17 |
Correct |
72 ms |
19172 KB |
Output is correct |
18 |
Correct |
91 ms |
21532 KB |
Output is correct |
19 |
Correct |
522 ms |
90972 KB |
Output is correct |
20 |
Correct |
263 ms |
68076 KB |
Output is correct |
21 |
Correct |
35 ms |
10152 KB |
Output is correct |
22 |
Incorrect |
291 ms |
64608 KB |
Output isn't correct |
23 |
Halted |
0 ms |
0 KB |
- |