結果

問題 No.2712 Play more!
ユーザー harurunharurun
提出日時 2024-03-31 15:21:52
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,629 bytes
コンパイル時間 9,615 ms
コンパイル使用メモリ 424,320 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-03-31 15:22:04
合計ジャッジ時間 8,204 ms
ジャッジサーバーID
(参考情報)
judge13 / 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 WA -
testcase_05 AC 2 ms
6,676 KB
testcase_06 AC 2 ms
6,676 KB
testcase_07 AC 72 ms
6,676 KB
testcase_08 AC 72 ms
6,676 KB
testcase_09 AC 72 ms
6,676 KB
testcase_10 WA -
testcase_11 AC 31 ms
6,676 KB
testcase_12 AC 161 ms
6,676 KB
testcase_13 AC 14 ms
6,676 KB
testcase_14 AC 98 ms
6,676 KB
testcase_15 AC 166 ms
6,676 KB
testcase_16 AC 11 ms
6,676 KB
testcase_17 AC 5 ms
6,676 KB
testcase_18 AC 21 ms
6,676 KB
testcase_19 AC 6 ms
6,676 KB
testcase_20 AC 33 ms
6,676 KB
testcase_21 AC 16 ms
6,676 KB
testcase_22 AC 146 ms
6,676 KB
testcase_23 AC 8 ms
6,676 KB
testcase_24 AC 17 ms
6,676 KB
testcase_25 AC 5 ms
6,676 KB
testcase_26 AC 23 ms
6,676 KB
testcase_27 AC 31 ms
6,676 KB
testcase_28 AC 11 ms
6,676 KB
testcase_29 AC 20 ms
6,676 KB
testcase_30 AC 166 ms
6,676 KB
testcase_31 AC 7 ms
6,676 KB
testcase_32 AC 7 ms
6,676 KB
testcase_33 AC 2 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <deque>
#include <queue>
#include <string>
#include <iomanip>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <utility>
#include <stack>
#include <random>
#include <complex>
#include <functional>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
#include <assert.h>
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
#endif
#if __has_include(<boost/multiprecision/cpp_int.hpp>)
#include <boost/multiprecision/cpp_int.hpp>
using cpp_int=boost::multiprecision::cpp_int;
#endif
#if __has_include(<boost/multiprecision/cpp_dec_float.hpp>)
#include <boost/multiprecision/cpp_dec_float.hpp>
template<unsigned size>using cpp_float=boost::multiprecision::number<boost::multiprecision::cpp_dec_float<size>>;
template<unsigned size>using cpp_double=boost::multiprecision::number<boost::multiprecision::cpp_dec_float<size,long long>>;
#endif
using namespace std;
using ll=long long;
#define read(x) cin>>(x);
#define readll(x) ll (x);cin>>(x);
#define readS(x) string (x);cin>>(x);
#define readvll(x,N) vector<ll> (x)((N));for(int i=0;i<(N);i++){cin>>(x)[i];}
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
#define rep2d(i,j,H,W) for(ll (i)=0;(i)<(H);(i)++)for(ll (j)=0;(j)<(W);j++)
#define is_in(x,y) (0<=(x) && (x)<H && 0<=(y) && (y)<W)
#define yn {cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}
#define double_out(x) fixed << setprecision(x)
template<class T> inline void erase_duplicate(vector<T>& A){sort(A.begin(),A.end());A.erase(unique(A.begin(),A.end()),A.end());}
inline ll powll(ll x,ll n){ll r=1;while(n>0){if(n&1){r*=x;};x*=x;n>>=1;};return r;}

struct Edge{
  ll from,to,cost;
};

int main(){
  ll N,M;
  cin>>N>>M;
  vector<Edge> E(M+N);
  vector<ll> A(N);
  for(ll i=0;i<N;i++){
    cin>>A[i];
    E[i]={i,i+N,-A[i]};
  }
  for(ll i=0;i<M;i++){
    ll u,v,c;
    cin>>u>>v>>c;
    if(u==N){
      continue;
    }
    E[i+N]={u+N-1,v-1,c};
  }
  const ll INF=numeric_limits<ll>::max();
  vector<ll> d(2*N,INF);
  d[0]=0;
  for(ll i=0;i<2*N;i++){
    ll f=1;
    for(Edge e:E){
        if(d[e.from]==INF){
            continue;
        }
        if(d[e.to]>d[e.from]+e.cost){
            f=0;
            d[e.to]=d[e.from]+e.cost;
        };
    }
    if(f){
        break;
    }
    if(2*N-1==i){
        cout<<"inf"<<endl;
        return 0;
    }
   }
    for(Edge e:E){
        if(d[e.from]==INF){
            continue;
        }
        if(d[e.from]+e.cost<d[e.to]){
            cout<<"inf"<<endl;
            return 0;
        }
    }
    cout<<-d[2*N-1]<<endl;
}
0