結果

問題 No.1 道のショートカット
ユーザー cormoran
提出日時 2016-11-14 01:13:37
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 1,637 bytes
コンパイル時間 2,046 ms
コンパイル使用メモリ 168,436 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-08 04:34:18
合計ジャッジ時間 3,906 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1 WA * 3
other AC * 2 WA * 34 RE * 4
権限があれば一括ダウンロードができます

ソースコード

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(V);
        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<bool> visited(V);
        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]) continue;
            visited[now.index] = true;
            for(Vertex &nxt : E[now.index]) {
                if(not visited[nxt.index] and now.cost + nxt.cost <= C) {
                    que.push(State{
                            nxt.index, now.cost + nxt.cost, now.time + nxt.time });
                }
            }
        }
        cout << -1 << endl;
        return 0;
    }
};

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