Submission #1221082

#TimeUsernameProblemLanguageResultExecution timeMemory
1221082VMaksimoski008Crocodile's Underground City (IOI11_crocodile)C++17
0 / 100
1 ms724 KiB
#include "crocodile.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;

int travel_plan(int n, int m, int R[][2], int L[], int k, int P[]) {
    vector<pll> g[n];
    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] });
    }

    vector<ll> D(n, 1e18), b1(n, 1e18), b2(n, 1e18);
    priority_queue<pll, vector<pll>, greater<pll> > pq;
    for(int i=0; i<k; i++) {
        D[P[i]] = b1[P[i]] = b2[P[i]] = 0;
        pq.push({ 0, P[i] });
    }

    while(!pq.empty()) {
        auto [d, u] = pq.top(); pq.pop();
        if(d != b2[u]) continue;
        D[u] = b2[u];

        for(auto [v, w] : g[u]) {
            if(d + w <= b2[v]) {
                if(d + w <= b1[v]) {
                    b2[v] = b1[v];
                    b1[v] = d + w;
                } else b2[v] = d + w;
                pq.push({ b2[v], v });
            }
        }
    }

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