#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<int,int>>>adj(N);
for (int 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 int maxn = 1e9;
priority_queue<pair<long long,long long>>q;
q.push({0,0});
vector<vector<long long>>dist(N,vector<long long>(2,maxn));
dist[0][0] = 0;
dist[0][1] = 0;
vector<bool>visited(N,false);
while(!q.empty()){
auto u = q.top();
q.pop();
visited[u.second] = false;
for (auto x:adj[u.second]){
if (dist[x.first][0] > dist[u.second][0] + x.second){
dist[x.first][1] = dist[x.first][0];
dist[x.first][0] = dist[u.second][0] + x.second;
if (!visited[x.first]){
visited[x.first] = true;
q.push({-dist[x.first][1],x.first});
}
}
else if (dist[x.first][1] > dist[u.second][0] + x.second){
dist[x.first][1] = dist[u.second][0] + x.second;
if (!visited[x.first]){
visited[x.first] = true;
q.push({-dist[x.first][1],x.first});
}
}
}
}
long long ans = 0;
for (int i = 0;i<K;++i){
if (dist[P[i]][0]!=maxn)
ans = max(ans,dist[P[i]][0]);
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |