結果

問題 No.2712 Play more!
ユーザー maeshunmaeshun
提出日時 2024-03-31 22:11:15
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,830 bytes
コンパイル時間 4,794 ms
コンパイル使用メモリ 270,256 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-03-31 22:11:22
合計ジャッジ時間 6,520 ms
ジャッジサーバーID
(参考情報)
judge12 / 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 54 ms
6,676 KB
testcase_08 AC 54 ms
6,676 KB
testcase_09 AC 55 ms
6,676 KB
testcase_10 AC 2 ms
6,676 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 7 ms
6,676 KB
testcase_14 AC 93 ms
6,676 KB
testcase_15 AC 36 ms
6,676 KB
testcase_16 AC 6 ms
6,676 KB
testcase_17 WA -
testcase_18 AC 6 ms
6,676 KB
testcase_19 AC 4 ms
6,676 KB
testcase_20 AC 15 ms
6,676 KB
testcase_21 WA -
testcase_22 AC 26 ms
6,676 KB
testcase_23 AC 6 ms
6,676 KB
testcase_24 AC 7 ms
6,676 KB
testcase_25 WA -
testcase_26 AC 9 ms
6,676 KB
testcase_27 AC 14 ms
6,676 KB
testcase_28 AC 24 ms
6,676 KB
testcase_29 AC 7 ms
6,676 KB
testcase_30 AC 118 ms
6,676 KB
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 AC 2 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
#define rep(i, n) for(int i=0;i<(n);++i)
#define rep1(i, n) for(int i=1;i<=(n);i++)
#define ll long long
using mint = modint998244353;
using P = pair<ll,ll>;
using lb = long double;
using T = tuple<ll, ll, ll>;
#ifdef LOCAL
#  include <debug_print.hpp>
#  define dbg(...) debug_print::multi_print(#__VA_ARGS__, __VA_ARGS__)
#else
#  define dbg(...) (static_cast<void>(0))
#endif

int main()
{
    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    vector<vector<pair<int, int>>> g(n), rev(n);
    rep(i,m){
        int a, b, c;
        cin >> a >> b >> c;
        --a;--b;
        g[a].emplace_back(b,c);
        rev[b].emplace_back(a,c);
    }
    vector<int> cnt(n);
    queue<int> q;
    q.push(0);
    while(!q.empty()) {
        int u = q.front();q.pop();
        cnt[u]++;
        if(u==n-1) continue;
        for(auto [v, c] : g[u]) {
            if(cnt[v]==0) {
                q.push(v);
            }
        }
    }
    q.push(n-1);
    while(!q.empty()) {
        int u = q.front();q.pop();
        cnt[u]++;
        for(auto [v, c] :rev[u]) {
            if(cnt[v]==1) {
                q.push(v);
            }
        }
    }
    vector<ll> dist(n, -1e18);
    dist[0] = 0;
    dbg(cnt);
    rep(j,2*n+1) {
        bool upd = false;
        rep(i,n-1){
            if(cnt[i]!=2) continue;
            for(auto [v, c] : g[i]) {
                if(cnt[v]!=2) continue;
                if(dist[v]<dist[i] + a[i]-c) {
                    dist[v] = dist[i] + a[i] - c;
                    upd = true;
                }
            }
       }
       if(j==2*n && upd) {
            cout << "inf" << endl;
            return 0;
       }
    }
    cout << dist[n-1] + a[n-1] << endl;
    return 0;
}
0