#include "crocodile.h"
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 10;
const int INF = 1e9 + 7;
vector <int> exits;
vector <pair <int, int> > adj[MAXN];
int n, m, dis[MAXN], dis2[MAXN], vis[MAXN];
int Dijkstra(){
priority_queue <pair <int, int>,vector <pair <int, int> >, greater <pair <int, int> > > pq;
memset(dis,63,sizeof(dis)); memset(dis2,63,sizeof(dis2));
for(auto u : exits) dis[u]=0, dis2[u]=0, pq.push({0,u});
while(!pq.empty()){
int s = pq.top().second; pq.pop();
if(vis[s]) continue; vis[s]=1;
for(auto cur : adj[s]){
int u = cur.first, w = cur.second;
if(dis[u]>dis2[s]+w){
dis2[u]=dis[u], dis[u]=dis2[s]+w;
pq.push({dis2[u],u});
}
else if(dis2[u]>dis2[s]+w)
dis2[u]=dis2[s]+w, pq.push({dis2[u],u});
}
}
return dis2[0];
}
int travel_plan(int N, int M, int R[][2], int L[], int k, int p[]) {
n = N, m = M;
for(int i = 0; i < m; i++) {
int a = R[i][0], b = R[i][1], c = L[i];
adj[a].push_back({b,c}), adj[b].push_back({a,c});
}
for(int i = 0; i < k; i++) exits.push_back(p[i]);
return Dijkstra();
}
Compilation message
crocodile.cpp: In function 'int Dijkstra()':
crocodile.cpp:16:9: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
16 | if(vis[s]) continue; vis[s]=1;
| ^~
crocodile.cpp:16:30: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
16 | if(vis[s]) continue; vis[s]=1;
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
3412 KB |
Output is correct |
2 |
Correct |
2 ms |
3412 KB |
Output is correct |
3 |
Correct |
2 ms |
3412 KB |
Output is correct |
4 |
Correct |
3 ms |
3444 KB |
Output is correct |
5 |
Correct |
3 ms |
3540 KB |
Output is correct |
6 |
Correct |
3 ms |
3412 KB |
Output is correct |
7 |
Correct |
2 ms |
3436 KB |
Output is correct |
8 |
Correct |
3 ms |
3540 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
3412 KB |
Output is correct |
2 |
Correct |
2 ms |
3412 KB |
Output is correct |
3 |
Correct |
2 ms |
3412 KB |
Output is correct |
4 |
Correct |
3 ms |
3444 KB |
Output is correct |
5 |
Correct |
3 ms |
3540 KB |
Output is correct |
6 |
Correct |
3 ms |
3412 KB |
Output is correct |
7 |
Correct |
2 ms |
3436 KB |
Output is correct |
8 |
Correct |
3 ms |
3540 KB |
Output is correct |
9 |
Correct |
3 ms |
3668 KB |
Output is correct |
10 |
Correct |
2 ms |
3412 KB |
Output is correct |
11 |
Correct |
3 ms |
3540 KB |
Output is correct |
12 |
Correct |
5 ms |
3924 KB |
Output is correct |
13 |
Correct |
6 ms |
3944 KB |
Output is correct |
14 |
Correct |
2 ms |
3412 KB |
Output is correct |
15 |
Correct |
3 ms |
3444 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
3412 KB |
Output is correct |
2 |
Correct |
2 ms |
3412 KB |
Output is correct |
3 |
Correct |
2 ms |
3412 KB |
Output is correct |
4 |
Correct |
3 ms |
3444 KB |
Output is correct |
5 |
Correct |
3 ms |
3540 KB |
Output is correct |
6 |
Correct |
3 ms |
3412 KB |
Output is correct |
7 |
Correct |
2 ms |
3436 KB |
Output is correct |
8 |
Correct |
3 ms |
3540 KB |
Output is correct |
9 |
Correct |
3 ms |
3668 KB |
Output is correct |
10 |
Correct |
2 ms |
3412 KB |
Output is correct |
11 |
Correct |
3 ms |
3540 KB |
Output is correct |
12 |
Correct |
5 ms |
3924 KB |
Output is correct |
13 |
Correct |
6 ms |
3944 KB |
Output is correct |
14 |
Correct |
2 ms |
3412 KB |
Output is correct |
15 |
Correct |
3 ms |
3444 KB |
Output is correct |
16 |
Correct |
335 ms |
58860 KB |
Output is correct |
17 |
Correct |
70 ms |
15172 KB |
Output is correct |
18 |
Correct |
94 ms |
16776 KB |
Output is correct |
19 |
Correct |
373 ms |
63504 KB |
Output is correct |
20 |
Correct |
214 ms |
50324 KB |
Output is correct |
21 |
Correct |
45 ms |
8704 KB |
Output is correct |
22 |
Correct |
240 ms |
46916 KB |
Output is correct |