Submission #20099855


Source Code Expand

#include <bits/stdc++.h>
using namespace std;
using Pair = pair<int64_t, int>;
using Graph = vector<vector<int>>;
using PQueue = priority_queue<Pair, vector<Pair>, greater<Pair>>;

vector<int> calc_safety(int N, int S, const Graph &graph, vector<int> &C_vec)
{
    vector<int> safety(N, S + 1);
    queue<int> que;
    for (int C : C_vec) {
        safety.at(C) = 0;
        que.push(C);
    }
    while (!que.empty()) {
        int s = que.front(); que.pop();
        int safety_s = safety.at(s);
        for (int d : graph.at(s)) {
            int safety_d = safety_s + 1;
            if (safety.at(d) <= safety_d)
                continue;
            safety.at(d) = safety_d;
            que.push(d);
        }
    }
    return safety;
}

vector<int64_t> calc_fee(const int64_t INF, int N, int S,
                    int64_t P, int64_t Q, const vector<int> &safety)
{
    vector<int64_t> fee(N, 0);
    for (int i = 1; i < N - 1; ++i) {
        if (safety.at(i) == 0)
            fee.at(i) = INF;
        else if (safety.at(i) <= S)
            fee.at(i) = Q;
        else
            fee.at(i) = P;
    }
    return fee;
}

int main()
{
    constexpr int64_t INF = 1e+11;
    int N, M, K, S;
    cin >> N >> M >> K >> S;
    int64_t P, Q;
    cin >> P >> Q;
    vector<int> C_vec(K);
    for (auto &C : C_vec) {
        cin >> C;
        --C;
    }
    Graph graph(N);
    for (int j = 0; j < M; ++j) {
        int A, B;
        cin >> A >> B;
        --A; --B;
        graph.at(A).push_back(B);
        graph.at(B).push_back(A);
    }
    auto safety = calc_safety(N, S, graph, C_vec);
    auto fee = calc_fee(INF, N, S, P, Q, safety);
    vector<int64_t> cost(N, INF);
    PQueue pq;
    cost.at(0) = 0;
    pq.push({0, 0});
    while (!pq.empty()) {
        auto top = pq.top(); pq.pop();
        auto s = top.second;
        auto cost_s = top.first;
        if (cost.at(s) < cost_s)
            continue;
        for (auto d : graph.at(s)) {
            auto cost_d = cost_s + fee.at(d);
            if (cost.at(d) <= cost_d)
                continue;
            cost.at(d) = cost_d;
            pq.push({cost_d, d});
        }
    }
    cout << cost.at(N - 1) << endl;
}

Submission Info

Submission Time
Task E - ゾンビ島 (Zombie Island)
User atug
Language C++ (GCC 9.2.1)
Score 100
Code Size 2182 Byte
Status AC
Exec Time 124 ms
Memory 11860 KiB

Judge Result

Set Name set01 set02 set03 set04 set05
Score / Max Score 20 / 20 20 / 20 20 / 20 20 / 20 20 / 20
Status
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
Set Name Test Cases
set01 data1
set02 data2
set03 data3
set04 data4
set05 data5
Case Name Status Exec Time Memory
data1 AC 9 ms 3528 KiB
data2 AC 65 ms 10480 KiB
data3 AC 13 ms 3704 KiB
data4 AC 124 ms 11860 KiB
data5 AC 116 ms 10820 KiB