이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "crocodile.h"
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100005;
const int inf = 1e9 + 7;
vector<pair<int, int>> adj[MAXN];
int dist[MAXN], dist1[MAXN], vis[MAXN];
bool isexit[MAXN];
int travel_plan(int nodes, int edges, int elist[][2], int elen[], int exits, int exarr[]){
for (int i = 0; i < edges; i++){
int a = elist[i][0], b = elist[i][1], d = elen[i];
adj[a].push_back({b, d});
adj[b].push_back({a, d});
}
priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq;
for (int i = 0; i < nodes; i++) dist[i] = dist1[i] = inf;
for (int i = 0; i < exits; i++){
dist[exarr[i]] = dist1[exarr[i]] = 0;
pq.push({0, exarr[i]});
vis[exarr[i]] = 1;
}
while (!pq.empty()){
int d = pq.top().first, x = pq.top().second; pq.pop();
if (d > dist1[x]) continue;
if (vis[x] > 1) continue;
if (vis[x] == 1){
for (auto nxt : adj[x]){
int nn = nxt.first, nd = nxt.second;
if (d + nd < dist[nn]){
dist1[nn] = dist[nn];
dist[nn] = d + nd;
pq.push({dist[nn], nn});
}
else if (d + nd < dist1[nn]){
dist1[nn] = d + nd;
pq.push({dist1[nn], x});
}
}
}
vis[x]++;
}
return dist1[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... |