結果

問題 No.2712 Play more!
ユーザー karinohitokarinohito
提出日時 2024-03-31 14:02:30
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 95 ms / 2,000 ms
コード長 1,423 bytes
コンパイル時間 2,789 ms
コンパイル使用メモリ 218,500 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-04-06 07:10:27
合計ジャッジ時間 4,806 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 2 ms
6,676 KB
testcase_05 AC 2 ms
6,676 KB
testcase_06 AC 2 ms
6,676 KB
testcase_07 AC 35 ms
6,676 KB
testcase_08 AC 34 ms
6,676 KB
testcase_09 AC 34 ms
6,676 KB
testcase_10 AC 2 ms
6,676 KB
testcase_11 AC 24 ms
6,676 KB
testcase_12 AC 29 ms
6,676 KB
testcase_13 AC 22 ms
6,676 KB
testcase_14 AC 27 ms
6,676 KB
testcase_15 AC 83 ms
6,676 KB
testcase_16 AC 33 ms
6,676 KB
testcase_17 AC 16 ms
6,676 KB
testcase_18 AC 9 ms
6,676 KB
testcase_19 AC 8 ms
6,676 KB
testcase_20 AC 32 ms
6,676 KB
testcase_21 AC 74 ms
6,676 KB
testcase_22 AC 36 ms
6,676 KB
testcase_23 AC 58 ms
6,676 KB
testcase_24 AC 19 ms
6,676 KB
testcase_25 AC 33 ms
6,676 KB
testcase_26 AC 10 ms
6,676 KB
testcase_27 AC 25 ms
6,676 KB
testcase_28 AC 22 ms
6,676 KB
testcase_29 AC 18 ms
6,676 KB
testcase_30 AC 31 ms
6,676 KB
testcase_31 AC 95 ms
6,676 KB
testcase_32 AC 59 ms
6,676 KB
testcase_33 AC 2 ms
6,676 KB
testcase_34 AC 2 ms
6,676 KB
testcase_35 AC 2 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int N, M;
    ll P;
    cin >> N >> M;
    
    vector<ll> S(N);
    for(int i=0;i<N;i++)cin>>S[i];
    vector<vector<pair<int, ll>>> G(N);
    vector<vector<int>> IG(N);
    for (int i = 0; i < M; i++) {
        ll A, B, C;
        cin >> A >> B >> C;
        A--; B--;
        G[A].push_back({ B,S[B]-C });
        IG[B].push_back(A);
    }

    vector<bool> CGOAL(N, 0);
    queue<int> Q;
    Q.push(N - 1);
    while (!Q.empty()) {
        int p = Q.front();
        Q.pop();
        if (CGOAL[p])continue;
        CGOAL[p] = 1;
        for (auto v : IG[p]) {
            if (!CGOAL[v])Q.push(v);
        }
    }
    // cout<<"P"<<endl;
    vector<ll> D(N, -1e18);
    D[0] = 0;
    for (ll m = 0; m < max(M, N) * 2; m++) {
        for (ll n = 0; n < N; n++) {
            for (auto v : G[n]) {
                ll nd = D[n] + v.second;
                ll nv = v.first;
                D[nv] = max(D[nv], nd);
            }
        }
    }
    bool E = 0;
    for (ll n = 0; n < N; n++) {
        for (auto v : G[n]) {
            ll nd = D[n] + v.second;
            ll nv = v.first;
            if (nd > D[nv]) {
                if (CGOAL[nv]&&D[nv]>-1e17)E = 1;
            }
        }
    }
    if (E)cout << "inf" << endl;
    else cout << max(0ll, D[N - 1]+S[0]) << endl;

}
0