結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 2 ms
6,548 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 97 ms
6,548 KB
testcase_10 AC 2 ms
6,548 KB
testcase_11 AC 117 ms
6,548 KB
testcase_12 AC 240 ms
6,548 KB
testcase_13 AC 166 ms
6,548 KB
testcase_14 AC 165 ms
6,548 KB
testcase_15 AC 343 ms
6,548 KB
testcase_16 AC 150 ms
6,548 KB
testcase_17 AC 86 ms
6,548 KB
testcase_18 AC 54 ms
6,548 KB
testcase_19 AC 51 ms
6,548 KB
testcase_20 AC 213 ms
6,548 KB
testcase_21 AC 215 ms
6,548 KB
testcase_22 AC 205 ms
6,548 KB
testcase_23 AC 182 ms
6,548 KB
testcase_24 AC 97 ms
6,548 KB
testcase_25 AC 131 ms
6,548 KB
testcase_26 AC 58 ms
6,548 KB
testcase_27 AC 124 ms
6,548 KB
testcase_28 AC 10 ms
6,548 KB
testcase_29 AC 139 ms
6,548 KB
testcase_30 AC 328 ms
6,548 KB
testcase_31 AC 4 ms
6,548 KB
testcase_32 AC 4 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 << 60);
#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, INF);
    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;
                    // cout << to << " " << dis[to] << endl;
                    if(i >= 7000 and to == n - 1) {
                        if(dis[to] < INF/2LL) {
                            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;
    }
    // cout << INF << endl;
    cout << - ret.back() << endl;
    return 0;
}
0