結果

問題 No.2712 Play more!
ユーザー littlegirl112littlegirl112
提出日時 2024-03-31 18:23:39
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 65 ms / 2,000 ms
コード長 1,832 bytes
コンパイル時間 2,072 ms
コンパイル使用メモリ 209,124 KB
実行使用メモリ 6,548 KB
最終ジャッジ日時 2024-04-03 12:11:20
合計ジャッジ時間 3,520 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,548 KB
testcase_01 AC 2 ms
6,548 KB
testcase_02 AC 1 ms
6,548 KB
testcase_03 AC 2 ms
6,548 KB
testcase_04 AC 2 ms
6,548 KB
testcase_05 AC 2 ms
6,548 KB
testcase_06 AC 2 ms
6,548 KB
testcase_07 AC 29 ms
6,548 KB
testcase_08 AC 29 ms
6,548 KB
testcase_09 AC 28 ms
6,548 KB
testcase_10 AC 2 ms
6,548 KB
testcase_11 AC 18 ms
6,548 KB
testcase_12 AC 20 ms
6,548 KB
testcase_13 AC 14 ms
6,548 KB
testcase_14 AC 27 ms
6,548 KB
testcase_15 AC 65 ms
6,548 KB
testcase_16 AC 13 ms
6,548 KB
testcase_17 AC 4 ms
6,548 KB
testcase_18 AC 6 ms
6,548 KB
testcase_19 AC 4 ms
6,548 KB
testcase_20 AC 28 ms
6,548 KB
testcase_21 AC 20 ms
6,548 KB
testcase_22 AC 20 ms
6,548 KB
testcase_23 AC 9 ms
6,548 KB
testcase_24 AC 11 ms
6,548 KB
testcase_25 AC 5 ms
6,548 KB
testcase_26 AC 6 ms
6,548 KB
testcase_27 AC 10 ms
6,548 KB
testcase_28 AC 3 ms
6,548 KB
testcase_29 AC 10 ms
6,548 KB
testcase_30 AC 42 ms
6,548 KB
testcase_31 AC 4 ms
6,548 KB
testcase_32 AC 3 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>
#include <atcoder/modint>
using mint = atcoder::modint998244353;
using namespace std;
using ll = long long;
using ld = long double;
template <class T = ll>
using vc = vector<T>;
template <class T = ll>
using vvc = vc<vc<T>>;
void solve();
int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    ll t = 1;
    // cin >> t;
    for (int i = 1; i <= t; i++) solve();
    return 0;
}
#define rep(i, a, b) for (ll i = (a); i < (b); i++)
ll dy[4] = {0, 1, 0, -1}, dx[4] = {1, 0, -1, 0};
struct Edge {
    ll from, to, cost;
    Edge(ll from, ll to, ll cost) : from(from), to(to), cost(cost) {}
};
void solve() {
    ll n, m;
    cin >> n >> m;
    vc<ll> A(n);
    rep(i, 0, n) cin >> A[i];
    vc<Edge> edges;
    const ll INF = 1LL << 60;
    auto bell = [&](vc<ll>& dist) -> bool {
        dist[0] = 0;
        rep(i, 0, n) {
            bool update = false;
            for (auto e : edges) {
                if (dist[e.from] == INF) continue;
                if (dist[e.to] > dist[e.from] + e.cost) {
                    dist[e.to] = dist[e.from] + e.cost;
                    update = true;
                }
            }
            if (!update) return false;
        }
        rep(i, 0, n) {
            for (auto e : edges) {
                if (dist[e.from] == INF) continue;
                if (dist[e.to] > dist[e.from] + e.cost) {
                    dist[e.to] = -INF;
                }
            }
        }
        return true;
    };
    vc<ll> dist(n, INF);
    rep(i, 0, m) {
        ll a, b, c;
        cin >> a >> b >> c;
        a--, b--;
        edges.push_back(Edge(a, b, c - A[b]));
    }
    bell(dist);
    if (dist[n - 1] == -INF) {
        cout << "inf" << endl;
        return;
    }
    cout << A[0] - dist[n - 1] << endl;
}
0