結果

問題 No.2712 Play more!
ユーザー Nzt3Nzt3
提出日時 2024-03-31 14:48:54
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 59 ms / 2,000 ms
コード長 999 bytes
コンパイル時間 2,473 ms
コンパイル使用メモリ 217,376 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-04-03 12:10:06
合計ジャッジ時間 4,113 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 40 ms
6,676 KB
testcase_08 AC 40 ms
6,676 KB
testcase_09 AC 40 ms
6,676 KB
testcase_10 AC 2 ms
6,676 KB
testcase_11 AC 12 ms
6,676 KB
testcase_12 AC 34 ms
6,676 KB
testcase_13 AC 10 ms
6,676 KB
testcase_14 AC 30 ms
6,676 KB
testcase_15 AC 49 ms
6,676 KB
testcase_16 AC 7 ms
6,676 KB
testcase_17 AC 3 ms
6,676 KB
testcase_18 AC 6 ms
6,676 KB
testcase_19 AC 5 ms
6,676 KB
testcase_20 AC 14 ms
6,676 KB
testcase_21 AC 8 ms
6,676 KB
testcase_22 AC 34 ms
6,676 KB
testcase_23 AC 4 ms
6,676 KB
testcase_24 AC 8 ms
6,676 KB
testcase_25 AC 4 ms
6,676 KB
testcase_26 AC 8 ms
6,676 KB
testcase_27 AC 27 ms
6,676 KB
testcase_28 AC 21 ms
6,676 KB
testcase_29 AC 7 ms
6,676 KB
testcase_30 AC 36 ms
6,676 KB
testcase_31 AC 59 ms
6,676 KB
testcase_32 AC 48 ms
6,676 KB
testcase_33 AC 2 ms
6,676 KB
testcase_34 AC 2 ms
6,676 KB
testcase_35 AC 2 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll=long long;

void chmin(ll &a ,ll b){
  a=min(a,b);
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N,M;
  cin>>N>>M;
  vector E(0,array<ll,3>());
  vector rG(N*2,vector(0,0));
  for(int i=0;i<N;i++){
    ll A;
    cin>>A;
    E.push_back({i,i+N,-A});
    rG[i+N].push_back(i);
  }
  for(int i=0;i<M;i++){
    ll A,B,C;
    cin>>A>>B>>C;
    --A,--B;
    E.push_back({A+N,B,C});
    rG[B].push_back(A+N);
  }
  vector vst(N*2,false);
  queue<int>bfs;
  bfs.push(N*2-1);
  vst[N*2-1]=1;
  while(bfs.size()){
    int v=bfs.front();
    bfs.pop();
    for(int i:rG[v]){
      if(!vst[i]){
        vst[i]=1;
        bfs.push(i);
      }
    }
  }
  vector dist(N*2,(ll)1e18);
  dist[0]=0;
  for(int i=0;i<N*2;i++){
    for(auto j:E){
      chmin(dist[j[1]],dist[j[0]]+j[2]);
    }
  }
  for(auto j:E){
    if(vst[j[1]]&&dist[j[0]]+j[2]<dist[j[1]]){
      cout<<"inf\n";
      return 0;
    }
  }
  cout<<-dist[N*2-1]<<'\n';
}
0