#include "crocodile.h"
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1000000;
const int INF = 1000000001;
vector<pair<int, int> > graph[MAX_N];
int dp[MAX_N];
int best[MAX_N][2];
void dijkstra(int N, int K, int P[]) {
priority_queue<pair<int, int> > pq;
for(int i = 0; i < K; ++i) {
dp[P[i]] = 0;
best[P[i]][0] = best[P[i]][1] = 0;
pq.push(make_pair(0, P[i]));
}
while(!pq.empty()) {
int nod = pq.top().second;
int cost = -pq.top().first;
pq.pop();
if(best[nod][1] == cost) {
dp[nod] = cost;
for(auto it: graph[nod]) {
int cost2 = cost + it.second;
if(cost2 < best[it.first][0]) {
best[it.first][1] = best[it.first][0];
best[it.first][0] = cost2;
pq.push({-best[it.first][1], it.first});
} else if(cost2 < best[it.first][1]) {
best[it.first][1] = cost2;
pq.push({-cost2, it.first});
}
}
}
}
}
int travel_plan(int N, int M, int R[][2], int L[], int K, int P[]) {
for(int i = 0; i < M; ++i) {
graph[R[i][0]].push_back(make_pair(R[i][1], L[i]));
graph[R[i][1]].push_back(make_pair(R[i][0], L[i]));
}
for(int i = 0; i < N; ++i) {
best[i][0] = INF;
best[i][1] = INF + 1;
dp[i] = INF;
}
dijkstra(N, K, P);
return dp[0];
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
23808 KB |
Output is correct |
2 |
Correct |
23 ms |
23808 KB |
Output is correct |
3 |
Correct |
27 ms |
23936 KB |
Output is correct |
4 |
Correct |
24 ms |
23928 KB |
Output is correct |
5 |
Correct |
23 ms |
23900 KB |
Output is correct |
6 |
Correct |
25 ms |
23936 KB |
Output is correct |
7 |
Correct |
24 ms |
23936 KB |
Output is correct |
8 |
Correct |
24 ms |
24036 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
23808 KB |
Output is correct |
2 |
Correct |
23 ms |
23808 KB |
Output is correct |
3 |
Correct |
27 ms |
23936 KB |
Output is correct |
4 |
Correct |
24 ms |
23928 KB |
Output is correct |
5 |
Correct |
23 ms |
23900 KB |
Output is correct |
6 |
Correct |
25 ms |
23936 KB |
Output is correct |
7 |
Correct |
24 ms |
23936 KB |
Output is correct |
8 |
Correct |
24 ms |
24036 KB |
Output is correct |
9 |
Correct |
24 ms |
24188 KB |
Output is correct |
10 |
Correct |
23 ms |
23936 KB |
Output is correct |
11 |
Correct |
23 ms |
23936 KB |
Output is correct |
12 |
Correct |
26 ms |
24320 KB |
Output is correct |
13 |
Correct |
26 ms |
24320 KB |
Output is correct |
14 |
Correct |
23 ms |
23928 KB |
Output is correct |
15 |
Correct |
23 ms |
23936 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
23808 KB |
Output is correct |
2 |
Correct |
23 ms |
23808 KB |
Output is correct |
3 |
Correct |
27 ms |
23936 KB |
Output is correct |
4 |
Correct |
24 ms |
23928 KB |
Output is correct |
5 |
Correct |
23 ms |
23900 KB |
Output is correct |
6 |
Correct |
25 ms |
23936 KB |
Output is correct |
7 |
Correct |
24 ms |
23936 KB |
Output is correct |
8 |
Correct |
24 ms |
24036 KB |
Output is correct |
9 |
Correct |
24 ms |
24188 KB |
Output is correct |
10 |
Correct |
23 ms |
23936 KB |
Output is correct |
11 |
Correct |
23 ms |
23936 KB |
Output is correct |
12 |
Correct |
26 ms |
24320 KB |
Output is correct |
13 |
Correct |
26 ms |
24320 KB |
Output is correct |
14 |
Correct |
23 ms |
23928 KB |
Output is correct |
15 |
Correct |
23 ms |
23936 KB |
Output is correct |
16 |
Correct |
652 ms |
65384 KB |
Output is correct |
17 |
Correct |
120 ms |
35100 KB |
Output is correct |
18 |
Correct |
178 ms |
36336 KB |
Output is correct |
19 |
Correct |
824 ms |
70332 KB |
Output is correct |
20 |
Correct |
323 ms |
59512 KB |
Output is correct |
21 |
Correct |
68 ms |
29432 KB |
Output is correct |
22 |
Incorrect |
363 ms |
55244 KB |
Output isn't correct |