結果

問題 No.1 道のショートカット
ユーザー KudeKude
提出日時 2020-08-27 22:32:08
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 4 ms / 5,000 ms
コード長 926 bytes
コンパイル時間 1,702 ms
コンパイル使用メモリ 172,424 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-20 16:51:41
合計ジャッジ時間 2,832 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 40
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define chmax(a, b) a = max(a, b);
#define chmin(a, b) a = min(a, b);
using namespace std;
using ll = long long;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<VI>;

const int INF = 1001001001;

struct Edge {
    int s;
    int t;
    int y;
    int m;
};

int main() {
    int n, c, v;
    cin >> n >> c >> v;
    vector<Edge> e(v);
    rep(i, v) cin >> e[i].s, e[i].s--;
    rep(i, v) cin >> e[i].t, e[i].t--;
    rep(i, v) cin >> e[i].y;
    rep(i, v) cin >> e[i].m;
    VVI dp(n, VI(c+1, INF));
    dp[0][0] = 0;
    rep(i, n) {
        rep(k, v) if (e[k].s == i) {
            int dest = e[k].t, cost = e[k].y;
            rep(j, c) if (j + cost <= c) chmin(dp[dest][j+cost], dp[i][j] + e[k].m);
        }
    }
    int ans = INF;
    rep(j, c+1) chmin(ans, dp[n-1][j]);
    if (ans == INF) ans = -1;
    cout << ans << endl;
}
0