#include "crocodile.h"
#include <bits/stdc++.h>
// #include <ext/rope>
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
// using namespace __gnu_cxx;
using namespace std;
// #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ll long long
#define ull unsigned long long
#define ld long double
#define pb push_back
#define bit(mask, i) ((mask >> i) & 1)
#define el '\n'
#define F first
#define S second
template <class X, class Y> bool maximize(X &x, const Y &y) { return (x < y ? x = y, 1 : 0); }
template <class X, class Y> bool minimize(X &x, const Y &y) { return (x > y ? x = y, 1 : 0); }
const int INF = 1e9;
const ll LINF = 1e18;
const int MOD = 1e9 + 7;
const int MULTI = 0;
const ld eps = 1e-9;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0}; // R D L U
const int ddx[4] = {-1, 1, 1, -1}, ddy[4] = {1, 1, -1, -1}; // UR DR DL UL
const char cx[4] = {'R', 'D', 'L', 'U'};
const ll base = 31;
const int nMOD = 2;
const ll mods[] = {(ll)1e9 + 10777, (ll)1e9 + 19777, (ll)1e9 + 3, (ll)1e9 + 3777};
const int maxn = 1e5 + 5;
int n, m, k, res;
vector<pair<int, int>> adj[maxn];
bool is_exit[maxn];
ll dist[2][maxn];
void opt(int u, ll d) {
if (d < dist[0][u])
dist[1][u] = dist[0][u], dist[0][u] = d;
else if (d < dist[1][u])
dist[1][u] = d;
}
void solve() {
priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>> pq;
for (int i = 1; i <= n; ++i)
if (is_exit[i]) {
pq.push(make_pair(0, i));
dist[0][i] = dist[1][i] = 0;
} else
dist[0][i] = dist[1][i] = LINF;
while (!pq.empty()) {
auto top = pq.top(); pq.pop();
ll d = top.F;
int u = top.S;
if (dist[1][u] != d) continue;
for (auto g: adj[u]) {
int v = g.F, w = g.S;
ll old = dist[1][v];
opt(v, d + w);
if (dist[1][v] != old)
pq.push(make_pair(dist[1][v], v));
}
}
res = dist[1][1];
}
int travel_plan(int N, int M, int R[][2], int L[], int K, int P[]) {
n = N; m = M;
for (int i = 0; i < m; ++i) {
int u = R[i][0] + 1, v = R[i][1] + 1, w = L[i];
adj[u].push_back(make_pair(v, w));
adj[v].push_back(make_pair(u, w));
}
k = K;
for (int i = 0; i < k; ++i)
is_exit[P[i] + 1] = true;
solve();
return res;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |