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;
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...)
#endif
int travel_plan(int n, int m, int r[][2], int l[], int k, int p[]) {
    vector<vector<int>> g(n);
    for (int i = 0; i < m; i++) {
        g[r[i][0]].emplace_back(i);
        g[r[i][1]].emplace_back(i);
    }
    vector<vector<int>> c(n);
    vector<int> d(n, (int) 1e9 + 1);
    priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq;
    for (int i = 0; i < k; i++) {
        c[p[i]].emplace_back(0);
        c[p[i]].emplace_back(0);
        d[p[i]] = 0;
        pq.emplace(0, p[i]);
    }
    while (!pq.empty()) {
        auto [e, v] = pq.top();
        pq.pop();
        if (d[v] != e) {
            continue;
        }
        if (v == 0) {
            break;
        }
        for (int id : g[v]) {
            int to = v ^ r[id][0] ^ r[id][1];
            c[to].emplace_back(d[v] + l[id]);
            if (c[to].size() > 1) {
                sort(c[to].begin(), c[to].end());
                if (c[to].size() > 2) {
                    c[to].resize(2);
                }
                if (d[to] > c[to][1]) {
                    d[to] = c[to][1];
                    pq.emplace(d[to], to);
                }
            }
        }
    }
    debug(d);
    return d[0];
}
#ifdef tabr
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m, k, r[100][2], l[100], p[100];
    cin >> n >> m >> k;
    for (int i = 0; i < m; i++) {
        cin >> r[i][0] >> r[i][1] >> l[i];
    }
    for (int i = 0; i < k; i++) {
        cin >> p[i];
    }
    debug(travel_plan(n, m, r, l, k, p));
    return 0;
}
#endif
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... |