結果

問題 No.1 道のショートカット
ユーザー latte0119
提出日時 2015-10-31 18:31:36
言語 C++11
(gcc 13.3.0)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 1,221 bytes
コンパイル時間 623 ms
コンパイル使用メモリ 63,996 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-20 16:17:43
合計ジャッジ時間 1,775 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 40
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<cstdio>
#include<vector>
#include<algorithm>
#include<iostream>
#include<cassert>
#include<cstring>
using namespace std;
typedef pair<int,int>pint;
typedef vector<int>vint;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);i++)
template<class T,class U>void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>void chmax(T &t,U f){if(t<f)t=f;}

struct edge{
    int to,cost,t;
    edge(int to,int cost,int t):to(to),cost(cost),t(t){}
};

int N,C,M;
vector<edge>G[50];

int X[1500],Y[1500],Z[1500],W[1500];
const int INF=1001001001;
int dp[50][301];
int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(0);

    cin>>N>>C>>M;
    rep(i,M)cin>>X[i];
    rep(i,M)cin>>Y[i];
    rep(i,M)cin>>Z[i];
    rep(i,M)cin>>W[i];

    rep(i,M){
        G[--X[i]].pb(edge(--Y[i],Z[i],W[i]));
    }

    fill_n(*dp,50*301,INF);
    dp[0][0]=0;
    rep(i,N){
        rep(j,C+1){
            rep(k,G[i].size()){
                edge &e=G[i][k];
                if(j+e.cost>C)continue;
                chmin(dp[e.to][j+e.cost],dp[i][j]+e.t);
            }
        }
    }

    int ans=*min_element(dp[N-1],dp[N-1]+C+1);
    if(ans==INF)cout<<"-1"<<endl;
    else cout<<ans<<endl;
    return 0;
}
0