#include "crocodile.h"
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
#define ll long long
#define pb push_back
#define pii pair<ll, ll>
#define f first;
#define s second;
#define oo 1000000000000000000ll
vector<vector<pii>> ed;
vector<bool> ext;
vector<int> visited;
vector<ll> res;
ll dijkstra(int n){
vector<ll> dist1(n, oo), dist2(n, oo);
vector<bool> visited(n);
priority_queue<pii, vector<pii>, greater<pii>> pq;
for (int i = 0; i < n; ++i) {
if (ext[i]) dist1[i] = dist2[i] = 0, pq.push({0, i});
}
while (!pq.empty()){
int cur = pq.top().s;
ll d = pq.top().f;
pq.pop();
if (visited[cur]) continue;
visited[cur] = true;
for (auto [to, l] : ed[cur]){
if (visited[to]) continue;
dist2[to] = min(dist2[to], d + l);
if (dist1[to] > dist2[to]) swap(dist1[to], dist2[to]);
pq.push({dist2[to], to});
}
}
return dist2[0];
}
int travel_plan(int n, int m, int r[][2], int l[], int k, int p[]){
ed.resize(n);
ext.resize(n);
visited.resize(n);
res.resize(n);
for (int i = 0; i < m; ++i) {
ed[r[i][0]].pb({r[i][1], l[i]});
ed[r[i][1]].pb({r[i][0], l[i]});
}
for (int i = 0; i < k; ++i) {
ext[p[i]] = true;
}
return (int)dijkstra(n);
}
Compilation message
crocodile.cpp: In function 'long long int dijkstra(int)':
crocodile.cpp:37:19: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
37 | for (auto [to, l] : ed[cur]){
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
296 KB |
Output is correct |
4 |
Correct |
1 ms |
460 KB |
Output is correct |
5 |
Correct |
1 ms |
460 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
2 ms |
480 KB |
Output is correct |
8 |
Correct |
1 ms |
432 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
296 KB |
Output is correct |
4 |
Correct |
1 ms |
460 KB |
Output is correct |
5 |
Correct |
1 ms |
460 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
2 ms |
480 KB |
Output is correct |
8 |
Correct |
1 ms |
432 KB |
Output is correct |
9 |
Correct |
4 ms |
844 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
2 ms |
460 KB |
Output is correct |
12 |
Correct |
5 ms |
1228 KB |
Output is correct |
13 |
Correct |
5 ms |
1228 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
460 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
296 KB |
Output is correct |
4 |
Correct |
1 ms |
460 KB |
Output is correct |
5 |
Correct |
1 ms |
460 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
2 ms |
480 KB |
Output is correct |
8 |
Correct |
1 ms |
432 KB |
Output is correct |
9 |
Correct |
4 ms |
844 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
2 ms |
460 KB |
Output is correct |
12 |
Correct |
5 ms |
1228 KB |
Output is correct |
13 |
Correct |
5 ms |
1228 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
460 KB |
Output is correct |
16 |
Correct |
861 ms |
96336 KB |
Output is correct |
17 |
Correct |
118 ms |
20920 KB |
Output is correct |
18 |
Correct |
142 ms |
23360 KB |
Output is correct |
19 |
Correct |
996 ms |
102688 KB |
Output is correct |
20 |
Correct |
645 ms |
73824 KB |
Output is correct |
21 |
Correct |
66 ms |
9028 KB |
Output is correct |
22 |
Correct |
580 ms |
63844 KB |
Output is correct |