結果

問題 No.2712 Play more!
ユーザー ensembleaverageensembleaverage
提出日時 2024-03-31 14:58:44
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 120 ms / 2,000 ms
コード長 2,449 bytes
コンパイル時間 1,768 ms
コンパイル使用メモリ 180,736 KB
実行使用メモリ 6,548 KB
最終ジャッジ日時 2024-04-03 12:10:21
合計ジャッジ時間 3,495 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 1 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 17 ms
6,548 KB
testcase_08 AC 17 ms
6,548 KB
testcase_09 AC 17 ms
6,548 KB
testcase_10 AC 2 ms
6,548 KB
testcase_11 AC 33 ms
6,548 KB
testcase_12 AC 13 ms
6,548 KB
testcase_13 AC 29 ms
6,548 KB
testcase_14 AC 15 ms
6,548 KB
testcase_15 AC 67 ms
6,548 KB
testcase_16 AC 54 ms
6,548 KB
testcase_17 AC 13 ms
6,548 KB
testcase_18 AC 7 ms
6,548 KB
testcase_19 AC 6 ms
6,548 KB
testcase_20 AC 50 ms
6,548 KB
testcase_21 AC 120 ms
6,548 KB
testcase_22 AC 14 ms
6,548 KB
testcase_23 AC 106 ms
6,548 KB
testcase_24 AC 22 ms
6,548 KB
testcase_25 AC 56 ms
6,548 KB
testcase_26 AC 7 ms
6,548 KB
testcase_27 AC 4 ms
6,548 KB
testcase_28 AC 4 ms
6,548 KB
testcase_29 AC 23 ms
6,548 KB
testcase_30 AC 28 ms
6,548 KB
testcase_31 AC 7 ms
6,548 KB
testcase_32 AC 7 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"

/*
#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);

//BFS/DFS
// 返り値なし(副作用 dist変化) miti/有向辺 a/頂点数 b/スタート地点 dist/bからの距離
void BFS(vvll &miti,ll s,vll &dist){ //mitiはmapでもおk
    dist[s]=1;
    queue<int> que;
    que.push(s);
    while(1){
        if(que.empty()) break;
        int r=que.front();
        que.pop();
        for(int i:miti[r]){
            if(dist[i]==0){
                que.push(i);
                dist[i]=1;
            }
        }
    }
}

//ベルマンフォード
struct edges{
  ll from;
  ll to;
  ll cost;
};
using ve=vector<edges>;
bool bellman(ve &miti,ll s,vll &dist,ll m,vll &cango){ //返り値 なし(副作用 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];
    
    vvll doro(n,vll(0));
    ve miti(m);
    ll a,b,c;
    rep(i,0,m){
        cin>>a>>b>>c; a--; b--;
        doro[b].push_back(a);
        miti[i]={a,b,c-d[a]};
    }
    vll cango(n);
    BFS(doro,n-1,cango);
    
    ve new_miti(0);
    rep(i,0,m){
        if(cango[miti[i].from]==1&&cango[miti[i].to]==1) new_miti.push_back({miti[i]});
    }
    vll dist(n,llINF);
    bool y=bellman(new_miti,0,dist,m,cango);
    if(y) cout<<"inf"<<endl;
    else cout<<d[n-1]-dist[n-1]<<endl;
}
0