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;
using ll = long long;
const int N = 1e5 + 10;
const ll INF = 1e15;
struct set2 {
    ll val[3];
    set2() {
        val[0] = val[1] = val[2] = INF;
    }
    void insert(ll x) {
        val[2] = x;
        if(val[1] > val[2]) swap(val[1], val[2]);
        if(val[0] > val[1]) swap(val[0], val[1]);
        if(val[1] > val[2]) swap(val[1], val[2]);
    }
};
set2 dp[N];
vector<pair<int, int>> g[N];
int travel_plan(int n, int m, int R[][2], int L[], int k, int P[]) {
    for(int i = 0; i < m; i++) {
        g[R[i][0]].push_back({R[i][1], L[i]});
        g[R[i][1]].push_back({R[i][0], L[i]});
    }
    set<pair<ll, int>> q;
    for(int i = 0; i < k; i++) {
        dp[P[i]].insert(0);
        dp[P[i]].insert(0);
    }
    for(int i = 0; i < n; i++) {
        q.insert({dp[i].val[1], i});
    }
    bool vis[N] = {};
    while(!q.empty()) {
        int s = q.begin()->second;
        if(dp[s].val[1] == INF) break;
        q.erase(q.begin());
        vis[s] = 1;
        for(auto [to, w] : g[s]) {
            if(vis[to]) continue;
            q.erase({dp[to].val[1], to});
            dp[to].insert(dp[s].val[1] + w);
            q.insert({dp[to].val[1], to});
        }
    }
    return dp[0].val[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... |