#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define all(s) s.begin(),s.end()
#define rall(s) s.rbegin(),s.rend()
int travel_plan(int N,int M,int R[][2],int L[],int K,int P[]){
vector<pair<int,int>>adj[N];
for(int i=0;i<M;i++){
adj[R[i][0]].pb({R[i][1],L[i]});
adj[R[i][1]].pb({R[i][0],L[i]});
}
vector<int>mn1(N,2e9),mn2(N,2e9);
vector<bool>end(N,false);
priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>>pq;
for(int i=0;i<K;i++){
end[P[i]]=true;
pq.push({0,P[i]});
}
while(!pq.empty()){
auto [D,i]=pq.top();
pq.pop();
if(mn2[i]<D) continue;
for(auto [j,l]:adj[i]){
if(!end[j]){
int newdist=D+l,bef=mn2[j];
if(newdist<mn1[j]){
mn2[j]=mn1[j];
mn1[j]=newdist;
}
else{
mn2[j]=min(mn2[j],newdist);
}
if(bef!=mn2[j]){
pq.push({mn2[j],j});
}
}
}
}
return mn2[0];
}
# |
결과 |
실행 시간 |
메모리 |
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 |
1 ms |
4600 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
1 ms |
4600 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
2 ms |
4604 KB |
Output is correct |
10 |
Correct |
1 ms |
4544 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
3 ms |
4700 KB |
Output is correct |
13 |
Correct |
3 ms |
4896 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4440 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
1 ms |
4600 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
2 ms |
4604 KB |
Output is correct |
10 |
Correct |
1 ms |
4544 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
3 ms |
4700 KB |
Output is correct |
13 |
Correct |
3 ms |
4896 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4440 KB |
Output is correct |
16 |
Correct |
282 ms |
52744 KB |
Output is correct |
17 |
Correct |
51 ms |
15016 KB |
Output is correct |
18 |
Correct |
64 ms |
16736 KB |
Output is correct |
19 |
Correct |
390 ms |
58024 KB |
Output is correct |
20 |
Correct |
208 ms |
44712 KB |
Output is correct |
21 |
Correct |
26 ms |
9052 KB |
Output is correct |
22 |
Correct |
219 ms |
42976 KB |
Output is correct |