#include "crocodile.h"
#include <bits/stdc++.h>
using namespace std;
int travel_plan(int N, int M, int R[][2], int L[], int K, int P[])
{
vector<vector<pair<long long,long long>>>adj(N);
for (long long i = 0;i<M;++i){
adj[R[i][0]].push_back({R[i][1],L[i]});
adj[R[i][1]].push_back({R[i][0],L[i]});
}
const long long maxn = 1e9;
vector<vector<long long>>dist(N,vector<long long>(2,maxn));
priority_queue<pair<long long,long long>>q;
for (long long i = 0;i<K;++i){
q.push({0,P[i]});
dist[P[i]][0] = 0;
dist[P[i]][1] = 0;
}
while(!q.empty()){
auto u = q.top();
q.pop();
for (auto x:adj[u.second]){
if (dist[x.first][0] > -u.first + x.second){
if (dist[x.first][1] > dist[x.first][0]){
dist[x.first][1] = dist[x.first][0];
q.push({-dist[x.first][1],x.first});
}
dist[x.first][0] = -u.first + x.second;
}
else if (dist[x.first][1] > -u.first + x.second){
dist[x.first][1] = -u.first + x.second;
q.push({-dist[x.first][1],x.first});
}
}
}
return dist[0][1];
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |