#include <bits/stdc++.h>
#include "crocodile.h"
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx,avx2,bmi,bmi2,popcnt,lzcnt")
using namespace std;
int travel_plan(int N, int M, int R[][2], int L[], int K, int P[])
{
vector<pair<int, int>> g[N];
for(int i = 0;i < M;i++){
g[R[i][0]].emplace_back(R[i][1], L[i]);
g[R[i][1]].emplace_back(R[i][0], L[i]);
}
long long dp[N];
for(int i = 0;i < N;i++) dp[i] = LONG_LONG_MAX;
for(int i = 0;i < K;i++) dp[P[i]] = 0;
for(int _ = 0;_ < N+2;_++){
for(int i = 0;i < N;i++){
long long m = LONG_LONG_MAX, s = LONG_LONG_MAX;
for(auto [to, c] : g[i]){
if(dp[to] == LONG_LONG_MAX) continue;
if(dp[to]+c <= m) {
s = m;
m = dp[to]+c;
} else if(dp[to]+c < s){
s = dp[to]+c;
}
}
dp[i] = min(dp[i], s);
}
}
return dp[0];
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
5 ms |
4444 KB |
Output is correct |
5 |
Correct |
5 ms |
4444 KB |
Output is correct |
6 |
Correct |
3 ms |
4444 KB |
Output is correct |
7 |
Correct |
5 ms |
4444 KB |
Output is correct |
8 |
Correct |
5 ms |
4444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
5 ms |
4444 KB |
Output is correct |
5 |
Correct |
5 ms |
4444 KB |
Output is correct |
6 |
Correct |
3 ms |
4444 KB |
Output is correct |
7 |
Correct |
5 ms |
4444 KB |
Output is correct |
8 |
Correct |
5 ms |
4444 KB |
Output is correct |
9 |
Correct |
4 ms |
4700 KB |
Output is correct |
10 |
Correct |
1 ms |
4440 KB |
Output is correct |
11 |
Correct |
2 ms |
4444 KB |
Output is correct |
12 |
Correct |
8 ms |
4696 KB |
Output is correct |
13 |
Correct |
5 ms |
5208 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
2 ms |
4444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
5 ms |
4444 KB |
Output is correct |
5 |
Correct |
5 ms |
4444 KB |
Output is correct |
6 |
Correct |
3 ms |
4444 KB |
Output is correct |
7 |
Correct |
5 ms |
4444 KB |
Output is correct |
8 |
Correct |
5 ms |
4444 KB |
Output is correct |
9 |
Correct |
4 ms |
4700 KB |
Output is correct |
10 |
Correct |
1 ms |
4440 KB |
Output is correct |
11 |
Correct |
2 ms |
4444 KB |
Output is correct |
12 |
Correct |
8 ms |
4696 KB |
Output is correct |
13 |
Correct |
5 ms |
5208 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
2 ms |
4444 KB |
Output is correct |
16 |
Execution timed out |
2041 ms |
55124 KB |
Time limit exceeded |
17 |
Halted |
0 ms |
0 KB |
- |