結果

問題 No.1 道のショートカット
ユーザー cormorancormoran
提出日時 2016-11-14 01:27:27
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,676 bytes
コンパイル時間 1,605 ms
コンパイル使用メモリ 160,704 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-27 22:01:58
合計ジャッジ時間 3,289 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 1 ms
4,380 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 2 ms
4,376 KB
testcase_33 AC 1 ms
4,376 KB
testcase_34 AC 2 ms
4,380 KB
testcase_35 AC 2 ms
4,376 KB
testcase_36 AC 1 ms
4,380 KB
testcase_37 AC 2 ms
4,376 KB
testcase_38 AC 1 ms
4,376 KB
testcase_39 AC 1 ms
4,376 KB
testcase_40 AC 2 ms
4,376 KB
testcase_41 AC 1 ms
4,376 KB
testcase_42 AC 1 ms
4,380 KB
testcase_43 AC 1 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i, j) for(int i=0; i < (int)(j); i++)
template<class T> istream& operator >> (istream &is , vector<T> &v) { for(T &a : v) is >> a; return is; }

struct Vertex {
    int index, cost, time;
};

using State = Vertex;

class Solver {
  public:
    bool solve() {
        int N, C, V; cin >> N >> C >> V;
        vector<int> S(V), T(V), Y(V), M(V);
        cin >> S >> T >> Y >> M;

        vector<vector<Vertex>> E(N);
        rep(i, V) {
            S[i]--; T[i]--;
            E[S[i]].push_back(Vertex{T[i], Y[i], M[i]});
            // E[T[i]].push_back(Vertex{S[i], Y[i], M[i]});
        }

        auto comp = [=](const State &a, const State &b) {
            return a.time > b.time; 
        };

        priority_queue<State, vector<State>, decltype(comp)> que(comp);
        que.push(State{0, 0, 0});

        vector<set<int>> visited(N);
        int ans = -1;
        while(que.size()) {
            State now = que.top(); que.pop();
            if(now.index == N - 1) {
                ans = now.time;
                break;
            }
            if(visited[now.index].count(now.cost)) continue;
            visited[now.index].insert(now.cost);
            for(Vertex &nxt : E[now.index]) {
                int c = now.cost + nxt.cost;
                if(not visited[nxt.index].count(c) and c <= C) {
                    que.push(State{
                            nxt.index, c, now.time + nxt.time });
                }
            }
        }
        cout << ans << endl;
        return 0;
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    Solver s;
    s.solve();
    return 0;
}
0