結果

問題 No.1 道のショートカット
ユーザー driipdriip
提出日時 2020-09-15 17:54:32
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,614 bytes
コンパイル時間 2,187 ms
コンパイル使用メモリ 208,272 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-04 01:51:02
合計ジャッジ時間 4,853 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
using tp = tuple<int, int, int>;

int s[1501], t[1501], y[1501], m[1501];

// vector<pii> adj;
vector<tp> adj[51];
int indeg[51];
int mincost[51], mintime[51];

int main() {
    #ifdef DEBUG
        freopen("in.txt", "r", stdin);
    #endif
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);

    int n, c, v; cin >> n >> c >> v;
    for (int i = 0; i < v; i++) cin >> s[i];
    for (int i = 0; i < v; i++) cin >> t[i];
    for (int i = 0; i < v; i++) cin >> y[i];
    for (int i = 0; i < v; i++) cin >> m[i];

    memset(mincost, 0x3f, sizeof(mincost));
    memset(mintime, 0x3f, sizeof(mintime));

    for (int i = 0; i < v; i++) {
        adj[s[i]].emplace_back(t[i], y[i], m[i]);  // start, end, cost, time
        indeg[t[i]]++;
    }

    assert(indeg[1] == 0);
    mincost[1] = mintime[1] = 0;

    queue<int> q;
    for (int i = 1; i <= n; i++) {
        if (!indeg[i]) {
            q.push(i);
        }
    }

    while (!q.empty()) {
        int x = q.front(); q.pop();

        for (auto [nx, ncost, ntime] : adj[x]) {
            if (mintime[nx] >= mintime[x] + ntime) {
                // check if cost overs c
                if (mincost[x] + ncost > c) {
                    continue;
                }
                mintime[nx] = mintime[x] + ntime;
                mincost[nx] = min(mincost[nx], mincost[x] + ncost);
            }
            indeg[nx]--;
            if (!indeg[nx]) q.push(nx);
        }
    }

    cout << (mintime[n] == 0x3f3f3f3f ? -1 : mintime[n]) << '\n';

    return 0;
}
0