Submission #99525

#TimeUsernameProblemLanguageResultExecution timeMemory
99525naoaiCrocodile's Underground City (IOI11_crocodile)C++14
100 / 100
898 ms52884 KiB
#include "crocodile.h"
#include <bits/stdc++.h>

using namespace std;

typedef long long i64;
static const int nmax = 1e5;
static const i64 inf = 1LL << 60;

i64 d[nmax + 1];
i64 mn[nmax + 1][2];

struct str {
    int x;
    i64 val;

    str () {}
    str (int _x, i64 _val) {
        x = _x, val = _val;
    }

    bool operator < (const str &shp) const {
        return val > shp.val;
    }
};
priority_queue<str> h;

bool viz[nmax + 1];
vector<pair<int, int>> g[nmax + 1];

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]});
    }

    for (int i = 0; i < N; ++ i) {
        mn[i][0] = mn[i][1] = inf;
        d[i] = inf;
    }

    for (int i = 0; i < K; ++ i) {
        mn[P[i]][0] = mn[P[i]][1] = 0;
        d[P[i]] = 0;
        h.push({P[i], 0});
    }

    while (!h.empty()) {
        str u = h.top();
        h.pop();

        if (viz[u.x] == 1)
            continue;
        viz[u.x] = 1;

        for (auto i : g[u.x]) {
            if (viz[i.first] == 1)
                continue;

            if (u.val + i.second <= mn[i.first][0]) {
                mn[i.first][1] = mn[i.first][0];
                mn[i.first][0] = u.val + i.second;
            } else if (u.val + i.second < mn[i.first][1]) {
                mn[i.first][1] = u.val + i.second;
            }

            if (mn[i.first][1] < d[i.first]) {
                d[i.first] = mn[i.first][1];
                h.push({i.first, d[i.first]});
            }
        }
    }

    return (int)d[0];
}


#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...