Submission #342805

# Submission time Handle Problem Language Result Execution time Memory
342805 2021-01-02T21:06:10 Z ThinGarfield Crocodile's Underground City (IOI11_crocodile) C++11
0 / 100
2 ms 2736 KB
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
#define f first
#define s second

constexpr int big = 1e9 + 9;
constexpr int maxn = 1e5 + 5;

vector<pii> adj[maxn];  // (vtx, wgt)
bool isexit[maxn];      // true if is exit
int mindist[maxn];      // minimum distance
int secdist[maxn];      // second-minimum distance (the answer)
bool done[maxn];
priority_queue<pair<pii, int>> q;  // (-mindist, -secdist, vtx)

int travel_plan(int n, int m, int r[][2], int l[], int k, int p[]) {
    // reading input
    for (int i = 0; i < m; i++) {
        int a = r[i][0], b = r[i][1], c = l[i];
        adj[a].push_back(make_pair(b, c));
        adj[b].push_back(make_pair(a, c));
    }
    for (int i = 0; i < k; i++) {
        isexit[p[i]] = true;
    }

    // setting up djikstra's things
    for (int i = 0; i < n; i++) {
        if (isexit[i]) {
            mindist[i] = 0;
            secdist[i] = 0;
            q.emplace(make_pair(make_pair(0, 0), i));
        } else {
            mindist[i] = big;
            secdist[i] = big;
        }
    }

    while (!q.empty()) {
        int vtx = q.top().s;
        q.pop();
        if (done[vtx]) continue;
        done[vtx] = true;
        for (pii nbr : adj[vtx]) {
            int nbrvtx = nbr.f;
            int wgt = nbr.s;
            int x = wgt + secdist[vtx];
            if (x < mindist[nbrvtx]) {
                secdist[nbrvtx] = mindist[nbrvtx];
                mindist[nbrvtx] = x;
                q.emplace(make_pair(make_pair(-mindist[nbrvtx], -secdist[vtx]), nbrvtx));
            } else if (x < secdist[nbrvtx]) {
                secdist[nbrvtx] = x;
                q.emplace(make_pair(make_pair(-mindist[nbrvtx], -secdist[vtx]), nbrvtx));
            }
        }
    }

    // for (int i = 0; i < n; i++) {
    //     cout << "node " << i << " : " << mindist[i] << ", " << secdist[i] << '\n';
    // }

    return secdist[0];
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2668 KB Output is correct
2 Incorrect 2 ms 2736 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2668 KB Output is correct
2 Incorrect 2 ms 2736 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2668 KB Output is correct
2 Incorrect 2 ms 2736 KB Output isn't correct
3 Halted 0 ms 0 KB -