結果

問題 No.2712 Play more!
ユーザー Today03
提出日時 2024-03-31 21:24:29
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,123 bytes
コンパイル時間 2,295 ms
コンパイル使用メモリ 200,980 KB
最終ジャッジ日時 2025-02-20 18:23:43
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 31 WA * 2
権限があれば一括ダウンロードができます

ソースコード

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);
    for (int i = 0; i < M; i++) {
        int a, b;
        ll c;
        cin >> a >> b >> c;
        a--;
        b--;
        G[a].push_back({b, c});
    }

    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 (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