結果

問題 No.2712 Play more!
ユーザー Today03Today03
提出日時 2024-03-31 21:28:18
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 68 ms / 2,000 ms
コード長 1,540 bytes
コンパイル時間 2,416 ms
コンパイル使用メモリ 218,080 KB
実行使用メモリ 6,548 KB
最終ジャッジ日時 2024-04-03 12:11:25
合計ジャッジ時間 3,778 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,548 KB
testcase_01 AC 2 ms
6,548 KB
testcase_02 AC 2 ms
6,548 KB
testcase_03 AC 2 ms
6,548 KB
testcase_04 AC 2 ms
6,548 KB
testcase_05 AC 1 ms
6,548 KB
testcase_06 AC 2 ms
6,548 KB
testcase_07 AC 28 ms
6,548 KB
testcase_08 AC 27 ms
6,548 KB
testcase_09 AC 27 ms
6,548 KB
testcase_10 AC 2 ms
6,548 KB
testcase_11 AC 10 ms
6,548 KB
testcase_12 AC 49 ms
6,548 KB
testcase_13 AC 13 ms
6,548 KB
testcase_14 AC 49 ms
6,548 KB
testcase_15 AC 55 ms
6,548 KB
testcase_16 AC 7 ms
6,548 KB
testcase_17 AC 4 ms
6,548 KB
testcase_18 AC 6 ms
6,548 KB
testcase_19 AC 5 ms
6,548 KB
testcase_20 AC 20 ms
6,548 KB
testcase_21 AC 11 ms
6,548 KB
testcase_22 AC 31 ms
6,548 KB
testcase_23 AC 7 ms
6,548 KB
testcase_24 AC 7 ms
6,548 KB
testcase_25 AC 5 ms
6,548 KB
testcase_26 AC 7 ms
6,548 KB
testcase_27 AC 15 ms
6,548 KB
testcase_28 AC 7 ms
6,548 KB
testcase_29 AC 9 ms
6,548 KB
testcase_30 AC 68 ms
6,548 KB
testcase_31 AC 7 ms
6,548 KB
testcase_32 AC 7 ms
6,548 KB
testcase_33 AC 2 ms
6,548 KB
testcase_34 AC 2 ms
6,548 KB
testcase_35 AC 2 ms
6,548 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#ifdef LOCAL
#include "./debug.cpp"
#else
#define debug(...)
#define print_line
#endif
using namespace std;
using ll = long long;

int main() {
    int N, M;
    cin >> N >> M;
    vector<ll> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    vector<vector<pair<int, ll>>> G(N);
    vector<vector<int>> rG(N);
    for (int i = 0; i < M; i++) {
        int a, b;
        ll c;
        cin >> a >> b >> c;
        a--;
        b--;
        G[a].push_back({b, c});
        rG[b].push_back(a);
    }

    vector<bool> reach(N, false);
    reach[N - 1] = true;
    queue<int> Q;
    Q.push(N - 1);
    while (!Q.empty()) {
        int now = Q.front();
        Q.pop();
        for (auto nxt : rG[now]) {
            if (reach[nxt]) {
                continue;
            }
            reach[nxt] = true;
            Q.push(nxt);
        }
    }

    vector<ll> dst(N, LLONG_MIN);
    dst[0] = A[0];
    for (int i = 0; i < N; i++) {
        bool fin = true;
        for (int j = 0; j < N; j++) {
            if (!reach[j] || dst[j] == LLONG_MIN) {
                continue;
            }
            for (auto [nxt, cost] : G[j]) {
                if (dst[nxt] < dst[j] - cost + A[nxt]) {
                    dst[nxt] = dst[j] - cost + A[nxt];
                    fin = false;
                }
            }
        }
        if (fin) {
            break;
        }
        if (i == N - 1) {
            cout << "inf" << endl;
            return 0;
        }
    }
    cout << dst[N - 1] << endl;
}
0