結果
| 問題 | No.2712 Play more! | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2024-03-31 16:26:18 | 
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 51 ms / 2,000 ms | 
| コード長 | 1,139 bytes | 
| コンパイル時間 | 2,426 ms | 
| コンパイル使用メモリ | 207,696 KB | 
| 最終ジャッジ日時 | 2025-02-20 18:05:54 | 
| ジャッジサーバーID (参考情報) | judge5 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 33 | 
ソースコード
#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;
                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;
}
            
            
            
        