이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
vector<vector<int>>dist(N,vector<int>(2,maxn));
priority_queue<pair<int,int>>q;
for (int i = 0;i<K;++i){
q.push({0,P[i]});
dist[P[i]][0] = 0;
dist[P[i]][1] = 0;
}
vector<int>visited(N,false);
while(!q.empty()){
auto u = q.top();
q.pop();
for (auto x:adj[u.second]){
if (dist[x.first][0] > dist[u.second][1] + x.second){
dist[x.first][1] = dist[x.first][0];
dist[x.first][0] = dist[u.second][1] + x.second;
q.push({-dist[x.first][1],x.first});
}
else if (dist[x.first][1] > dist[u.second][1] + x.second){
dist[x.first][1] = dist[u.second][1] + x.second;
q.push({-dist[x.first][1],x.first});
}
}
}
return dist[0][1];
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |