#include <bits/stdc++.h>
#include "crocodile.h"
using namespace std;
int n, m, x, y;
long long w, inf = 1e18;
vector<pair<int, long long>> adj[100001];
long long dist[100001][2];
priority_queue<pair<long long, int>, vector<pair<long long, int>>, greater<pair<long long, int>>> q;
int travel_plan(int N, int M, int R[][2], int L[], int K, int P[])
{
ios_base::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
for (int i = 0; i < M; i++) {
x = R[i][0], y = R[i][1], w = L[i];
adj[x].push_back({y, w});
adj[y].push_back({x, w});
}
for (int i = 0; i < N; i++) dist[i][0] = dist[i][1] = inf;
for (int i = 0; i < K; i++) {
dist[P[i]][0] = dist[P[i]][1] = 0;
q.push({0, P[i]});
}
while (!q.empty()) {
long long val = q.top().first;
int u = q.top().second;
q.pop();
for (pair<int, long long> v : adj[u]) {
if (dist[v.first][1] > val + v.second) {
dist[v.first][1] = val + v.second;
if (dist[v.first][0] > dist[v.first][1]) swap(dist[v.first][0], dist[v.first][1]);
q.push({val + v.second, v.first});
}
}
}
return dist[0][1];
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |