이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "crocodile.h"
#include <bits/stdc++.h>
using namespace std;
#define ss second
#define ff first
typedef long long ll;
// #define int ll
int mod = 1e9+7;
int travel_plan(int N, int M, int R[][2],
int L[], int k, int p[]){
int n = N, m = M;
vector<vector<pair<int,int>>> adj(n);
for(int i = 0; i < m; ++i){
int a = R[i][0],b = R[i][1],c = L[i];
adj[a].push_back({c,b});
adj[b].push_back({c,a});
}
for(int i = 0; i < n; ++i){
sort(adj[i].begin(), adj[i].end());
}
priority_queue<pair<ll,ll>, vector<pair<ll,ll>>, greater<pair<ll,ll>>> pq;
vector<vector<ll>> dis(2,vector<ll>(n, 1e18));
for(int i = 0; i < k; ++i){
pq.push({0,p[i]});
dis[0][p[i]] = 0;
dis[1][p[i]] = 0;
}
while(!pq.empty()){
pair<int,int> a = pq.top(); pq.pop();
if(dis[1][a.ss]!=a.ff){
continue;
}
for(auto &[w, nxt] : adj[a.ss]){
if(a.ff+w<dis[0][nxt]){
if(dis[0][nxt]!=dis[1][nxt]){
pq.push({dis[0][nxt], nxt});
}
swap(dis[0][nxt], dis[1][nxt]);
dis[0][nxt] = a.ff+w;
}else if(a.ff+w<dis[1][nxt]){
dis[1][nxt] = a.ff+w;
pq.push({dis[1][nxt], nxt});
}
}
}
return dis[1][0];
}
// signed main(){
// ios_base::sync_with_stdio(false);
// cin.tie(NULL);
// // ifstream cin ("shortcut.in");
// // ofstream cout ("shortcut.out");
// return 0;
// }
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |