結果

問題 No.2712 Play more!
ユーザー ensembleaverageensembleaverage
提出日時 2024-03-31 14:48:56
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,760 bytes
コンパイル時間 1,851 ms
コンパイル使用メモリ 171,636 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-03-31 14:49:00
合計ジャッジ時間 3,494 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 1 ms
6,676 KB
testcase_04 WA -
testcase_05 AC 2 ms
6,676 KB
testcase_06 AC 1 ms
6,676 KB
testcase_07 AC 17 ms
6,676 KB
testcase_08 AC 17 ms
6,676 KB
testcase_09 AC 17 ms
6,676 KB
testcase_10 WA -
testcase_11 AC 35 ms
6,676 KB
testcase_12 AC 15 ms
6,676 KB
testcase_13 AC 32 ms
6,676 KB
testcase_14 AC 14 ms
6,676 KB
testcase_15 AC 77 ms
6,676 KB
testcase_16 AC 53 ms
6,676 KB
testcase_17 AC 13 ms
6,676 KB
testcase_18 AC 9 ms
6,676 KB
testcase_19 AC 5 ms
6,676 KB
testcase_20 AC 52 ms
6,676 KB
testcase_21 AC 121 ms
6,676 KB
testcase_22 AC 20 ms
6,676 KB
testcase_23 AC 105 ms
6,676 KB
testcase_24 AC 23 ms
6,676 KB
testcase_25 AC 55 ms
6,676 KB
testcase_26 AC 6 ms
6,676 KB
testcase_27 AC 5 ms
6,676 KB
testcase_28 AC 4 ms
6,676 KB
testcase_29 AC 22 ms
6,676 KB
testcase_30 AC 32 ms
6,676 KB
testcase_31 AC 6 ms
6,676 KB
testcase_32 AC 6 ms
6,676 KB
testcase_33 AC 2 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"

/*
#include "boost/multiprecision/cpp_int.hpp"
namespace mp = boost::multiprecision;
using i128=mp::cpp_int;
*/

using namespace std;
typedef long long ll;
typedef int64_t i64;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<double> vd;
typedef vector<vd> vvd;
#define rep(i,a,n) for(int i=a;i<n;i++)
#define drep(i,a,n) for(int i=a;i>n;i--)
#define yes(ans) if(ans)cout<<"yes"<<endl;else cout<<"no"<<endl;
#define Yes(ans) if(ans)cout<<"Yes"<<endl;else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl;else cout<<"NO"<<endl;
#define iINF 1000000007
#define lINF 10000000000007
#define llINF 4000000000000000007
#define all(x) x.begin(),x.end()
#define so(x) sort(all(x))
#define re(x) reverse(all(x))
const double PI = acos(-1);

//ベルマンフォード
struct edges{
  ll from;
  ll to;
  ll cost;
};
using ve=vector<edges>;
bool bellman(ve &miti,ll s,vll &dist,ll m){ //返り値 なし(副作用 distが変わる)
  dist[s]=0;
  ll y=1;
  ll cnt=0;
  while(y){
    if(cnt>m){
        return 1;
    }
    y=0;
    for(auto i:miti){
      if(dist[i.from]+i.cost<dist[i.to]){
        dist[i.to]=dist[i.from]+i.cost;
        y=1;
      }
    }
    cnt++;
  }
  return 0;
}

int main(){
    ll n,m; cin>>n>>m;
    vll d(n); rep(i,0,n) cin>>d[i];
    
    ve miti(m);
    ll a,b,c;
    rep(i,0,m){
        cin>>a>>b>>c; a--; b--;
        miti[i]={a,b,c-d[a]};
    }
    
    vll dist(n,llINF);
    bool y=bellman(miti,0,dist,m);
    //cout<<dist[n-1]<<endl;
    if(y) cout<<"inf"<<endl;
    else cout<<d[n-1]-dist[n-1]<<endl;
}
0