Submission #1196347

#TimeUsernameProblemLanguageResultExecution timeMemory
1196347AMel0nCrocodile's Underground City (IOI11_crocodile)C++20
0 / 100
0 ms320 KiB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
#define FOR(N) for(int i = 0; i < N; i++)
#define VI vector<int>
#define PII pair<int,int>
#define F first
#define S second
#define all(x) (x).begin(), (x).end()


int travel_plan(int N, int M, int R[][2], int L[], int K, int P[]) {
    vector<vector<PII>> adj(N, vector<PII>());
    
    priority_queue<PII, vector<PII>, greater<>> pq; // second best dist because first best will be blocked, n
    vector<PII> vis(N, {LLONG_MAX, LLONG_MAX}); // best, second best
    vector<bool> seen(N, false);

    FOR(M) {
        int a = R[i][0]; 
        int b = R[i][1];
        int d = L[i];
        adj[a].push_back({b, d});
        adj[b].push_back({a, d});
    }
    FOR(K){
        vis[P[i]] = {0,0};
        pq.push({0, P[i]});
    }

    while(pq.size()){
        int d = pq.top().F;
        int n = pq.top().S;
        pq.pop();
        if (seen[n]) continue;
        seen[n] = true;
        //cout << d << ' ' << n << ' ' << vis[n].F << ' ' << vis[n].S << endl;

        for(auto c: adj[n]) {
            if (vis[c.F].F > d + c.S) {
                vis[c.F].S = vis[c.F].F;
                vis[c.F].F = d + c.S;
            } else if (vis[c.F].S > d + c.S) { 
                vis[c.F].S = d + c.S;
            }
            if (vis[c.F].S != LLONG_MAX) pq.push({vis[c.F].S, c.F});
            //cout << c.F << ' ' << vis[c.F].F << ' '<< vis[c.F].S << endl;
        }
    }
    return vis[0].S;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...