#include "crocodile.h"
#include<bits/stdc++.h>
#define ll long long
using namespace std;
vector<bool>is,vis;
vector<vector<pair<int,int>>>v;
vector<priority_queue<int>>dp;
const int INF=1e9;
int travel_plan(int N, int M, int R[][2], int L[], int K, int P[]){
is.assign(N,false);
vis.assign(N,false);
for(int i=0;i<K;i++) is[P[i]]=true;
v.resize(N);
for(int i=0;i<M;i++){
v[R[i][0]].push_back({R[i][1],L[i]});
v[R[i][1]].push_back({R[i][0],L[i]});
}
dp.resize(N);
priority_queue<pair<int,int>>q;
for(int i=0;i<K;i++){
q.push({0,P[i]});
dp[P[i]].push(0);
}
while(!q.empty()){
auto [d,x]=q.top();
q.pop();
if(vis[x]) continue;
vis[x]=true;
for(auto [z,w]:v[x]){
if(dp[z].size()<2){
dp[z].push(dp[x].top()+w);
q.push({-dp[z].top(),z});
}
else if(dp[x].top()+w<dp[z].top()){
dp[z].pop();
dp[z].push(dp[x].top()+w);
q.push({-dp[z].top(),z});
}
}
}
return dp[0].top();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |