#include "crocodile.h"
#include<bits/stdc++.h>
using namespace std;
#define pii pair<long long,int>
#define fi first
#define se second
const long long inf = 1e18;
const int maxn = 1e5+5;
vector<pii> edge[maxn];
long long Min1[maxn],Min2[maxn];
int travel_plan(int N, int M, int R[][2], int L[], int K, int P[])
{
for(int i=0;i<M;i++){
int u=R[i][0],v=R[i][1];
edge[u].push_back({L[i],v});
edge[v].push_back({L[i],u});
}
for(int i=0;i<N;i++) Min1[i]=Min2[i]=inf;
priority_queue<pii,vector<pii>,greater<pii>> pq;
for(int i=0;i<K;i++){
Min1[P[i]]=Min2[P[i]]=0;
pq.push({0,P[i]});
}
while(!pq.empty()){
auto [d,u]=pq.top();pq.pop();
if(Min2[u]!=d) continue;
for(auto [w,v]:edge[u]){
if(d+w<Min1[v]){
if(Min1[v]<Min2[v]){
Min2[v]=Min1[v];
pq.push({Min2[v],v});
}
Min1[v]=d+w;
}
else if(d+w<Min2[v]){
Min2[v]=d+w;
pq.push({d+w,v});
}
}
}
return Min2[0];
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
2 ms |
2644 KB |
Output is correct |
3 |
Correct |
2 ms |
2644 KB |
Output is correct |
4 |
Correct |
2 ms |
2772 KB |
Output is correct |
5 |
Correct |
2 ms |
2772 KB |
Output is correct |
6 |
Correct |
2 ms |
2644 KB |
Output is correct |
7 |
Correct |
2 ms |
2772 KB |
Output is correct |
8 |
Correct |
2 ms |
2772 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
2 ms |
2644 KB |
Output is correct |
3 |
Correct |
2 ms |
2644 KB |
Output is correct |
4 |
Correct |
2 ms |
2772 KB |
Output is correct |
5 |
Correct |
2 ms |
2772 KB |
Output is correct |
6 |
Correct |
2 ms |
2644 KB |
Output is correct |
7 |
Correct |
2 ms |
2772 KB |
Output is correct |
8 |
Correct |
2 ms |
2772 KB |
Output is correct |
9 |
Correct |
3 ms |
3028 KB |
Output is correct |
10 |
Correct |
1 ms |
2664 KB |
Output is correct |
11 |
Correct |
2 ms |
2772 KB |
Output is correct |
12 |
Correct |
4 ms |
3412 KB |
Output is correct |
13 |
Correct |
3 ms |
3412 KB |
Output is correct |
14 |
Correct |
1 ms |
2644 KB |
Output is correct |
15 |
Correct |
2 ms |
2772 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
2 ms |
2644 KB |
Output is correct |
3 |
Correct |
2 ms |
2644 KB |
Output is correct |
4 |
Correct |
2 ms |
2772 KB |
Output is correct |
5 |
Correct |
2 ms |
2772 KB |
Output is correct |
6 |
Correct |
2 ms |
2644 KB |
Output is correct |
7 |
Correct |
2 ms |
2772 KB |
Output is correct |
8 |
Correct |
2 ms |
2772 KB |
Output is correct |
9 |
Correct |
3 ms |
3028 KB |
Output is correct |
10 |
Correct |
1 ms |
2664 KB |
Output is correct |
11 |
Correct |
2 ms |
2772 KB |
Output is correct |
12 |
Correct |
4 ms |
3412 KB |
Output is correct |
13 |
Correct |
3 ms |
3412 KB |
Output is correct |
14 |
Correct |
1 ms |
2644 KB |
Output is correct |
15 |
Correct |
2 ms |
2772 KB |
Output is correct |
16 |
Correct |
320 ms |
83044 KB |
Output is correct |
17 |
Correct |
54 ms |
17612 KB |
Output is correct |
18 |
Correct |
72 ms |
20080 KB |
Output is correct |
19 |
Correct |
437 ms |
89280 KB |
Output is correct |
20 |
Correct |
226 ms |
67980 KB |
Output is correct |
21 |
Correct |
29 ms |
9660 KB |
Output is correct |
22 |
Correct |
238 ms |
64108 KB |
Output is correct |