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>
#include "crocodile.h"
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pli = pair<ll, int>;
#define F first
#define S second
const int N = 150010;
const ll INF = 1e18;
ll dist1[N], dist2[N];
bool vis[N];
vector<pii> G[N];
int travel_plan(int n, int m, int R[][2], int L[], int k, int P[])
{
fill(dist1, dist1+n, INF);
fill(dist2, dist2+n, INF);
for (int i = 0; i < m; ++i) {
int u = R[i][0], v = R[i][1], w = L[i];
G[u].push_back({v, w});
G[v].push_back({u, w});
}
priority_queue<pli, vector<pli>, greater<pli>> Q;
for (int i = 0; i < k; ++i) {
dist1[P[i]] = dist2[P[i]] = 0;
Q.push({0, P[i]});
}
while (!Q.empty()) {
int u = Q.top().second;
Q.pop();
if (vis[u]) continue;
vis[u] = true;
for (auto v : G[u]) if (!vis[v.F]) {
bool mod = false;
if (dist2[u]+v.S < dist1[v.F]) {
dist2[v.F] = dist1[v.F];
dist1[v.F] = dist2[u]+v.S;
mod = true;
} else if (dist2[u]+v.S < dist2[v.F]) {
dist2[v.F] = dist2[u]+v.S;
mod = true;
}
if (mod && dist2[v.F] < INF)
Q.push({dist2[v.F], v.F});
}
}
return dist2[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... |