結果

問題 No.2712 Play more!
ユーザー shinchanshinchan
提出日時 2024-03-31 15:04:49
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,890 bytes
コンパイル時間 2,206 ms
コンパイル使用メモリ 209,972 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-03-31 15:04:56
合計ジャッジ時間 6,544 ms
ジャッジサーバーID
(参考情報)
judge12 / judge10
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,548 KB
testcase_01 AC 2 ms
6,548 KB
testcase_02 AC 2 ms
6,548 KB
testcase_03 AC 2 ms
6,548 KB
testcase_04 AC 3 ms
6,548 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 99 ms
6,548 KB
testcase_10 AC 2 ms
6,548 KB
testcase_11 AC 80 ms
6,548 KB
testcase_12 AC 243 ms
6,548 KB
testcase_13 AC 129 ms
6,548 KB
testcase_14 AC 168 ms
6,548 KB
testcase_15 AC 332 ms
6,548 KB
testcase_16 AC 77 ms
6,548 KB
testcase_17 AC 49 ms
6,548 KB
testcase_18 AC 53 ms
6,548 KB
testcase_19 AC 30 ms
6,548 KB
testcase_20 AC 174 ms
6,548 KB
testcase_21 AC 141 ms
6,548 KB
testcase_22 AC 232 ms
6,548 KB
testcase_23 AC 145 ms
6,548 KB
testcase_24 AC 48 ms
6,548 KB
testcase_25 AC 103 ms
6,548 KB
testcase_26 AC 62 ms
6,548 KB
testcase_27 AC 133 ms
6,548 KB
testcase_28 AC 10 ms
6,548 KB
testcase_29 AC 97 ms
6,548 KB
testcase_30 AC 300 ms
6,548 KB
testcase_31 AC 4 ms
6,548 KB
testcase_32 AC 5 ms
6,548 KB
testcase_33 AC 2 ms
6,548 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define all(v) (v).begin(),(v).end()
#define pb(a) push_back(a)
#define rep(i, n) for(int i=0;i<n;i++)
#define foa(e, v) for(auto&& e : v)
using ll = long long;
const ll MOD7 = 1000000007, MOD998 = 998244353, INF = (1LL << 55);
#define dout(a) cout<<fixed<<setprecision(10)<<a<<endl;

bool flag = 0;
//bellman_ford
template <typename T>
std::vector<ll> bellman_ford(T &G, int start, int lim = -1){
    // T -> vector<vector<pair<ll, int or ll>>> 
    // edge pair<ll, ll> -> pair<cost, to>
    int n = G.size();
    std::vector<ll> dis(n, (1LL << 59));
    dis[start] = 0;
    
    lim = 20000;

    for(int i = 0; i < lim; i ++) {// 2N 回やると検出とか楽
        bool update = 0;
        for(int j = 0; j < n; j ++) {
            for(auto [cost, to] : G[j]) {
                if(dis[j] + cost < dis[to]) {
                    dis[to] = dis[j] + cost;
                    if(i >= 7000 and to == n - 1) {
                        if(dis[to] < n * (1LL << 30)) {
                            flag = 1;
                            return dis;
                        }
                    }
                    
                    update = 1;
                }
            }
        }
        if(!update) break;
    }
    return dis; 
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, m;
    cin >> n >> m;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    vector<vector<pair<ll, ll>>> v(n * 2);
    rep(i, m) {
        ll x, y, c;
        cin >> x >> y >> c;
        x --; y --;
        v[x * 2 + 1].push_back({c, y * 2});
    }
    rep(i, n) v[i*2].push_back({-a[i], i*2+1});

    auto ret = bellman_ford(v, 0);
    if(flag) {
        cout << "inf" << endl;
        return 0;
    }
    assert(-(1LL << 30) * n <= ret.back() and ret.back() <= (1LL << 30) * n);
    cout << - ret.back() << endl;
    return 0;
}
0