Submission #721977

#TimeUsernameProblemLanguageResultExecution timeMemory
721977Jarif_RahmanCrocodile's Underground City (IOI11_crocodile)C++17
100 / 100
556 ms93460 KiB
#include <bits/stdc++.h>
#define pb push_back
#define f first
#define sc second
using namespace std;
typedef long long int ll;
typedef string str;

const ll inf = 1e17;

int travel_plan(int n, int m, int R[][2], int L[], int k, int P[]){
    vector<vector<pair<int, ll>>> graph(n);
    for(int i = 0; i < m; i++){
        graph[R[i][0]].pb({R[i][1], L[i]});
        graph[R[i][1]].pb({R[i][0], L[i]});
    }

    vector<ll> dis0(n, inf), dis(n, inf);
    vector<bool> bl(n, 0);
    priority_queue<pair<ll, int>> pq;

    for(int i = 0; i < k; i++){
        dis0[P[i]] = 0, dis[P[i]] = 0;
        pq.push({0, P[i]});
    }

    while(!pq.empty()){
        int nd = pq.top().sc; pq.pop();
        if(bl[nd]) continue;
        bl[nd] = 1;
        for(auto [x, w]: graph[nd]) if(dis[nd]+w < dis[x]){
            if(dis[nd]+w < dis0[x]) dis[x] = dis0[x], dis0[x] = dis[nd]+w;
            else dis[x] = dis[nd]+w;
            pq.push({-dis[x], x});
        }
    }

    return dis[0];
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...