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>
#define ll long long
#define ld long double
#define pii pair<int, int>
#define pll pair<ll, ll>
using namespace std;
 
const ll INF = 1e15;
vector<vector<pll>> adj;
int travel_plan(int n, int m, int R[][2], int L[], int k, int P[]) {
    vector<ll> dist(n, INF);
    adj.resize(n);
    for (int i = 0; i < m; i++) {
        adj[R[i][0]].push_back({L[i], R[i][1]});
        adj[R[i][1]].push_back({L[i], R[i][0]});
    }
    
    for (int i = 0; i < n; i++) sort(adj[i].begin(), adj[i].end());
    
    vector<bool> can(n, false);
    priority_queue<pll, vector<pll>, greater<pll>> q;
    for (int i = 0; i < k; i++) {
        q.push({0, P[i]});
        can[P[i]] = true;
    }
    
    while (!q.empty()) {
        auto p = q.top();
        q.pop();
        ll curr_cost = p.first, node = p.second;
        
        if (can[node] && curr_cost >= dist[node]) continue;
        if (!can[node]) {
            can[node] = true;
            continue;
        }
        dist[node] = curr_cost;
        for (int i = 0; i < adj[node].size(); i++) {
            ll edge_cost = adj[node][i].first, dest = adj[node][i].second;
            if (curr_cost + edge_cost < dist[dest]) {
//                dist[dest] = curr_cost + edge_cost;
                q.push({curr_cost + edge_cost, dest});
            }
        }
    }
    
    return dist[0];
    
}
//int32_t main() {
//    ios_base::sync_with_stdio(false);
//    cin.tie(nullptr);
//
////    int n = 5, m = 7, k = 2;
////    int R[][2] = {{0, 2}, {0, 3}, {3, 2}, {2, 1}, {0, 1}, {0, 4}, {3, 4}};
////    int L[] = {4, 3, 2, 10, 100, 7, 9};
////    int P[] = {1, 3};
//
////    int n = 5, m = 4, k = 3;
////    int R[][2] = {{0, 1}, {0, 2}, {3, 2}, {2, 4}};
////    int L[] = {2, 3, 1, 4};
////    int P[] = {1, 3, 4};
//
////    cout << travel_plan(n, m, R, L, k, P);
//
//    int n, m, k;
//    cin >> n >> m >> k;
//
//    int R[m][2], L[m], P[k];
//    for (int i = 0; i < m; i++) {
//        int u, v, cost;
//        cin >> u >> v >> cost;
//        R[i][0] = u, R[i][1] = v;
//        L[i] = cost;
//    }
//    for (int i = 0; i < k; i++) {
//        cin >> P[i];
//    }
//
//    cout << travel_plan(n, m, R, L, k, P) << '\n';
//}
Compilation message (stderr)
crocodile.cpp: In function 'int travel_plan(int, int, int (*)[2], int*, int, int*)':
crocodile.cpp:39:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |         for (int i = 0; i < adj[node].size(); i++) {
      |                         ~~^~~~~~~~~~~~~~~~~~| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... |