結果

問題 No.2712 Play more!
ユーザー GOTKAKOGOTKAKO
提出日時 2024-03-31 16:26:44
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,188 bytes
コンパイル時間 2,256 ms
コンパイル使用メモリ 215,320 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-03-31 16:26:49
合計ジャッジ時間 3,538 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 WA -
testcase_05 AC 2 ms
6,676 KB
testcase_06 AC 2 ms
6,676 KB
testcase_07 AC 22 ms
6,676 KB
testcase_08 AC 21 ms
6,676 KB
testcase_09 AC 22 ms
6,676 KB
testcase_10 WA -
testcase_11 AC 10 ms
6,676 KB
testcase_12 AC 25 ms
6,676 KB
testcase_13 AC 8 ms
6,676 KB
testcase_14 AC 21 ms
6,676 KB
testcase_15 AC 42 ms
6,676 KB
testcase_16 AC 6 ms
6,676 KB
testcase_17 AC 4 ms
6,676 KB
testcase_18 AC 5 ms
6,676 KB
testcase_19 AC 4 ms
6,676 KB
testcase_20 AC 10 ms
6,676 KB
testcase_21 AC 8 ms
6,676 KB
testcase_22 AC 27 ms
6,676 KB
testcase_23 AC 6 ms
6,676 KB
testcase_24 AC 6 ms
6,676 KB
testcase_25 AC 5 ms
6,676 KB
testcase_26 AC 6 ms
6,676 KB
testcase_27 AC 20 ms
6,676 KB
testcase_28 AC 23 ms
6,676 KB
testcase_29 AC 6 ms
6,676 KB
testcase_30 AC 28 ms
6,676 KB
testcase_31 AC 30 ms
6,676 KB
testcase_32 AC 24 ms
6,676 KB
testcase_33 AC 2 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main() {
    int N,M; cin >> N >> M;
    vector<int> A(N);
    for(auto &a : A) cin >> a;
    vector<vector<pair<int,long long>>> Graph(N);
    for(int i=0; i<M; i++){
        int a,b,c; cin >> a >> b >> c;
        a--; b--;
        c = A.at(a)-c;
        Graph.at(a).push_back({b,c});
    }

    vector<long long> dist(N,-1e18);
    dist.at(0) = 0;
    for(int t=0; t<=N; t++){
        for(int i=0; i<N; i++){
            for(auto [to,c] : Graph.at(i)) dist.at(to) = max(dist.at(to),dist.at(i)+c);
        }
    }
    queue<int> Q;
    long long inf = 2e18;
    for(int i=0; i<N; i++){
        for(auto [to,c] : Graph.at(i)){
            if(dist.at(to) < dist.at(i)+c){
                dist.at(to) = inf;
                cout << "inf" << endl; return 0;
                Q.push(to);                
            }
        }
    }
    while(Q.size()){
        int pos = Q.front(); Q.pop();
        for(auto [to,ig] : Graph.at(pos)){
            if(dist.at(to) == inf) continue;
            dist.at(to) = inf; Q.push(to);
        }
    }

    if(dist.at(N-1) == inf) cout << "inf" << endl;
    else cout << dist.at(N-1)+A.at(N-1) << endl;
}
0