This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MX = 1e5 + 5, inf = 1e18;
ll dist[MX][2];
int N, M, K;
vector<pair<int, int>> g[MX];
int travel_plan(int _N, int _M, int r[][2], int l[], int _K, int p[]) {
N = _N, M = _M, K = _K;
for(int i = 0; i < MX; i++) {
dist[i][0] = dist[i][1] = inf;
}
for(int i = 0; i < M; i++) {
g[r[i][0]].push_back({r[i][1], l[i]});
g[r[i][1]].push_back({r[i][0], l[i]});
}
priority_queue<pair<ll,ll>> pq;
for(int i = 0; i < K; i++) {
dist[p[i]][0] = dist[p[i]][1] = 0;
for(auto [u, w] : g[p[i]]) {
pq.push({-w, u});
}
}
while(!pq.empty()) {
auto [d, v] = pq.top(); pq.pop();
d = -d;
if(d < dist[v][0]) {
dist[v][0] = d;
} else if(d < dist[v][1]) {
dist[v][1] = d;
for(auto [u, w] : g[v]) {
ll c = d + w;
if(c > 1e18) c = 1e18;
pq.push({-c, u});
}
}
}
return dist[0][1];
}
// int r[100][2], l[100], p[100];
// int main() {
// ios_base::sync_with_stdio(0); cin.tie(0);
// int N, M, K;
// cin >> N >> M >> K;
// for(int i = 0; i < M; i++) {
// cin >> r[i][0] >> r[i][1];
// }
// for(int i = 0; i < M; i++) cin >> l[i];
// for(int i = 0; i < K; i++) cin >> p[i];
// cout << travel_plan(N, M, r, l, K, p) << '\n';
// }
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |