結果

問題 No.1 道のショートカット
ユーザー odan3240odan3240
提出日時 2015-12-23 14:17:16
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 5 ms / 5,000 ms
コード長 1,798 bytes
コンパイル時間 1,366 ms
コンパイル使用メモリ 94,248 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-27 21:50:44
合計ジャッジ時間 2,164 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <algorithm>
#include <functional>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <climits>

#define all(c) (c).begin(), (c).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

const int INF=100000000;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
using namespace std;
typedef pair<int ,int > P;
typedef long long ll;

struct Edge {
    int to,cost,time;
};
struct State {
    int v,cost,time;
    bool operator<(const State &rhs) const {
        return time > rhs.time;
    }
};
int N,V;
int C;
int S[1503],T[1503],Y[1503],M[1503];
vector<Edge> G[51];
int dijk() {
    int d[51][302];
    rep(i,51) rep(j,302) d[i][j]=INF;
    rep(j,302) d[1][j]=0;
    priority_queue<State> que;
    que.push(State{1,0,0});
    while(que.size()) {
        State s=que.top(); que.pop();
        rep(i,G[s.v].size()) {
            Edge e=G[s.v][i];
            if(C>=s.cost+e.cost and d[e.to][s.cost+e.cost]>d[s.v][s.cost]+e.time) {
                d[e.to][s.cost+e.cost]=d[s.v][s.cost]+e.time;
                que.push(State{e.to,s.cost+e.cost,d[e.to][s.cost+e.cost]});
            }
        }
    }

    int ret=INF;
    ret = *min_element(d[N],d[N]+C+1);
    if(ret==INF) return -1;
    return ret;
}
int main() {
    cin>>N>>C>>V;
    rep(i,V) cin>>S[i];
    rep(i,V) cin>>T[i];
    rep(i,V) cin>>Y[i];
    rep(i,V) cin>>M[i];
    rep(i,V) {
        G[S[i]].push_back(Edge{T[i],Y[i],M[i]});
        //G[T[i]].push_back(Edge{S[i],Y[i],M[i]});
    }
    cout<<dijk()<<endl;
    return 0;
}
0