結果

問題 No.2712 Play more!
ユーザー t98slidert98slider
提出日時 2024-03-31 14:51:56
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 278 ms / 2,000 ms
コード長 1,755 bytes
コンパイル時間 2,242 ms
コンパイル使用メモリ 213,564 KB
実行使用メモリ 6,548 KB
最終ジャッジ日時 2024-04-03 12:10:12
合計ジャッジ時間 5,144 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,548 KB
testcase_01 AC 1 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 AC 2 ms
6,548 KB
testcase_06 AC 2 ms
6,548 KB
testcase_07 AC 76 ms
6,548 KB
testcase_08 AC 76 ms
6,548 KB
testcase_09 AC 75 ms
6,548 KB
testcase_10 AC 2 ms
6,548 KB
testcase_11 AC 44 ms
6,548 KB
testcase_12 AC 263 ms
6,548 KB
testcase_13 AC 29 ms
6,548 KB
testcase_14 AC 157 ms
6,548 KB
testcase_15 AC 278 ms
6,548 KB
testcase_16 AC 13 ms
6,548 KB
testcase_17 AC 4 ms
6,548 KB
testcase_18 AC 28 ms
6,548 KB
testcase_19 AC 7 ms
6,548 KB
testcase_20 AC 49 ms
6,548 KB
testcase_21 AC 15 ms
6,548 KB
testcase_22 AC 227 ms
6,548 KB
testcase_23 AC 5 ms
6,548 KB
testcase_24 AC 24 ms
6,548 KB
testcase_25 AC 4 ms
6,548 KB
testcase_26 AC 39 ms
6,548 KB
testcase_27 AC 40 ms
6,548 KB
testcase_28 AC 45 ms
6,548 KB
testcase_29 AC 26 ms
6,548 KB
testcase_30 AC 267 ms
6,548 KB
testcase_31 AC 89 ms
6,548 KB
testcase_32 AC 81 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>
using namespace std;
using ll = long long;
const ll INF2 = 1ll << 60;

vector<ll> Bellman_Ford(vector<vector<pair<ll,ll>>> &graph,int start){
    int n=graph.size(),x;
    vector<ll> dist(n,INF2);
    queue<int> next;
    dist[start]=0;
    int cnt=n-1;
    while(cnt--){
        for(int i=0;i<n;i++){
            if(dist[i]==INF2)continue;
            for(int j=0;j<graph[i].size();j++){
                if(dist[i]+graph[i][j].second<dist[graph[i][j].first]){
                    dist[graph[i][j].first]=dist[i]+graph[i][j].second;
                }
            }
        }
    }
    for(int i=0;i<n;i++){
        if(dist[i]==INF2)continue;
        for(int j=0;j<graph[i].size();j++){
            if(dist[graph[i][j].first]!=-INF2&&
                dist[i]+graph[i][j].second<dist[graph[i][j].first]){
                dist[graph[i][j].first]=-INF2;
                next.push(graph[i][j].first);
            }
        }
    }
    while(!next.empty()){
        x=next.front();
        next.pop();
        for(int j=0;j<graph[x].size();j++){
            if(dist[graph[x][j].first]!=-INF2){
                dist[graph[x][j].first]=-INF2;
                next.push(graph[x][j].first);
            }
        }
    }
    return dist;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m, v, u, c;
    cin >> n >> m;
    vector<vector<pair<ll,ll>>> g(2 * n);
    for(int i = 0; i < n; i++){
        cin >> c;
        g[i].emplace_back(i + n, -c);
    }
    for(int i = 0; i < m; i++){
        cin >> u >> v >> c;
        g[--u + n].emplace_back(--v, c);
    }
    auto dp = Bellman_Ford(g, 0);
    ll ans = dp.back();
    if(ans == -INF2){
        cout << "inf\n";
    }else{
        cout << -ans << '\n';
    }
}
0