#include <vector>
#include <algorithm>
#include <queue>
#define pb push_back
using namespace std;
typedef pair<int,int> pp;
vector<pp> edge[100010];
typedef long long ll;
ll dijk[100010];
ll scnd[100010];
typedef pair<ll,int> pd;
priority_queue<pd> pq;
int travel_plan(int N, int M, int R[][2], int L[], int K, int P[])
{
for(int i=0; i<N; ++i){
dijk[i]=(1LL<<62);
scnd[i]=(1LL<<62);
}
for(int i=0; i<K; ++i){
int a=P[i];
dijk[a]=0;
scnd[a]=0;
pq.push({scnd[a],a});
}
for(int i=0; i<N; ++i) edge[i].clear();
for(int i=0; i<M; ++i){
int a=R[i][0], b=R[i][1];
if(dijk[b]!=0) edge[a].pb({b, L[i]});
if(dijk[a]!=0) edge[b].pb({a, L[i]});
}
for(;pq.size();){
auto t=pq.top(); pq.pop();
int x=t.second;
if(scnd[x] != -t.first) continue;
//printf("Vis %d; second max %lld\n", x, scnd[x]);
for(pp yy:edge[x]){
int y=yy.first; int d=yy.second;
if(dijk[y]>scnd[x]+d){
//printf("Check to %d\n", y);
if(dijk[y]<scnd[y]){
//puts("Pull secondmin");
scnd[y] = dijk[y];
pq.push({-scnd[y],y});
}
dijk[y] = scnd[x]+d;
} else if(scnd[y] > scnd[x]+d){
scnd[y]=scnd[x]+d;
pq.push({-scnd[y],y});
}
}
}
return scnd[0];
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
122464 KB |
Output is correct |
2 |
Correct |
0 ms |
122464 KB |
Output is correct |
3 |
Correct |
0 ms |
122464 KB |
Output is correct |
4 |
Correct |
0 ms |
122464 KB |
Output is correct |
5 |
Correct |
0 ms |
122596 KB |
Output is correct |
6 |
Correct |
0 ms |
122464 KB |
Output is correct |
7 |
Correct |
0 ms |
122464 KB |
Output is correct |
8 |
Correct |
0 ms |
122464 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
122596 KB |
Output is correct |
2 |
Correct |
0 ms |
122464 KB |
Output is correct |
3 |
Correct |
0 ms |
122596 KB |
Output is correct |
4 |
Correct |
3 ms |
122728 KB |
Output is correct |
5 |
Correct |
3 ms |
122728 KB |
Output is correct |
6 |
Correct |
0 ms |
122464 KB |
Output is correct |
7 |
Correct |
0 ms |
122596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
623 ms |
149964 KB |
Output is correct |
2 |
Correct |
86 ms |
127216 KB |
Output is correct |
3 |
Correct |
133 ms |
128404 KB |
Output is correct |
4 |
Correct |
846 ms |
156068 KB |
Output is correct |
5 |
Correct |
359 ms |
145352 KB |
Output is correct |
6 |
Correct |
36 ms |
124840 KB |
Output is correct |
7 |
Correct |
373 ms |
140816 KB |
Output is correct |