#include "crocodile.h"
#include <bits/stdc++.h>
using namespace std;
vector < pair < int, int > > gr[111111];
int cnt[111111], min1[111111], min2[111111];
int travel_plan(int N, int M, int R[][2], int L[], int K, int P[])
{
for(int i = 0; i < M; i ++ ){
gr[R[i][0]].push_back({L[i], R[i][1]});
gr[R[i][1]].push_back({L[i], R[i][0]});
}
for( int i = 0; i < N; i ++ ){
min1[i] = min2[i] = 1e9;
}
set < pair < int, int > > q;
for( int i = 0; i < K; i ++ ){
min1[P[i]] = min2[P[i]] = 0;
q.insert({0, P[i]});
}
while(!q.empty()){
pair < int, int > pp = *q.begin(); q.erase(pp);
int v = pp.second;
for( auto edge: gr[v] ){
int cost = edge.first, to = edge.second;
if( min1[to] >= min2[v]+cost ){
q.erase({min2[to], to});
min2[to] = min1[to];
min1[to] = min2[v]+cost;
q.insert({min2[to], to});
}
else if( min2[to] > min2[v]+cost ){
q.erase({min2[to], to});
min2[to] = min2[v] + cost;
q.insert({min2[to], to});
}
}
}
/*
for( int i = 0; i < N; i ++ ){
cout << "min1[" << i <<"]=" << min1[i] << "; min2[" << i << "]="<<min2[i]<<endl;
}
*/
return min2[0];
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
2944 KB |
Output is correct |
2 |
Correct |
6 ms |
2944 KB |
Output is correct |
3 |
Correct |
6 ms |
3072 KB |
Output is correct |
4 |
Correct |
8 ms |
3072 KB |
Output is correct |
5 |
Correct |
7 ms |
3072 KB |
Output is correct |
6 |
Correct |
7 ms |
3072 KB |
Output is correct |
7 |
Correct |
7 ms |
3072 KB |
Output is correct |
8 |
Correct |
7 ms |
3072 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
2944 KB |
Output is correct |
2 |
Correct |
6 ms |
2944 KB |
Output is correct |
3 |
Correct |
6 ms |
3072 KB |
Output is correct |
4 |
Correct |
8 ms |
3072 KB |
Output is correct |
5 |
Correct |
7 ms |
3072 KB |
Output is correct |
6 |
Correct |
7 ms |
3072 KB |
Output is correct |
7 |
Correct |
7 ms |
3072 KB |
Output is correct |
8 |
Correct |
7 ms |
3072 KB |
Output is correct |
9 |
Correct |
8 ms |
3200 KB |
Output is correct |
10 |
Correct |
6 ms |
2944 KB |
Output is correct |
11 |
Correct |
7 ms |
3072 KB |
Output is correct |
12 |
Correct |
10 ms |
3328 KB |
Output is correct |
13 |
Correct |
10 ms |
3328 KB |
Output is correct |
14 |
Correct |
6 ms |
2944 KB |
Output is correct |
15 |
Correct |
7 ms |
3072 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
2944 KB |
Output is correct |
2 |
Correct |
6 ms |
2944 KB |
Output is correct |
3 |
Correct |
6 ms |
3072 KB |
Output is correct |
4 |
Correct |
8 ms |
3072 KB |
Output is correct |
5 |
Correct |
7 ms |
3072 KB |
Output is correct |
6 |
Correct |
7 ms |
3072 KB |
Output is correct |
7 |
Correct |
7 ms |
3072 KB |
Output is correct |
8 |
Correct |
7 ms |
3072 KB |
Output is correct |
9 |
Correct |
8 ms |
3200 KB |
Output is correct |
10 |
Correct |
6 ms |
2944 KB |
Output is correct |
11 |
Correct |
7 ms |
3072 KB |
Output is correct |
12 |
Correct |
10 ms |
3328 KB |
Output is correct |
13 |
Correct |
10 ms |
3328 KB |
Output is correct |
14 |
Correct |
6 ms |
2944 KB |
Output is correct |
15 |
Correct |
7 ms |
3072 KB |
Output is correct |
16 |
Correct |
648 ms |
40184 KB |
Output is correct |
17 |
Correct |
109 ms |
10872 KB |
Output is correct |
18 |
Correct |
169 ms |
12080 KB |
Output is correct |
19 |
Correct |
957 ms |
44024 KB |
Output is correct |
20 |
Correct |
337 ms |
36984 KB |
Output is correct |
21 |
Correct |
57 ms |
6648 KB |
Output is correct |
22 |
Correct |
388 ms |
31992 KB |
Output is correct |