結果

問題 No.2712 Play more!
ユーザー ku_senjanku_senjan
提出日時 2024-03-31 15:27:53
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 57 ms / 2,000 ms
コード長 1,784 bytes
コンパイル時間 2,741 ms
コンパイル使用メモリ 219,612 KB
実行使用メモリ 6,548 KB
最終ジャッジ日時 2024-04-03 12:10:36
合計ジャッジ時間 3,862 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 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 35 ms
6,548 KB
testcase_08 AC 35 ms
6,548 KB
testcase_09 AC 39 ms
6,548 KB
testcase_10 AC 2 ms
6,548 KB
testcase_11 AC 20 ms
6,548 KB
testcase_12 AC 28 ms
6,548 KB
testcase_13 AC 16 ms
6,548 KB
testcase_14 AC 34 ms
6,548 KB
testcase_15 AC 57 ms
6,548 KB
testcase_16 AC 14 ms
6,548 KB
testcase_17 AC 4 ms
6,548 KB
testcase_18 AC 7 ms
6,548 KB
testcase_19 AC 5 ms
6,548 KB
testcase_20 AC 29 ms
6,548 KB
testcase_21 AC 18 ms
6,548 KB
testcase_22 AC 29 ms
6,548 KB
testcase_23 AC 8 ms
6,548 KB
testcase_24 AC 12 ms
6,548 KB
testcase_25 AC 5 ms
6,548 KB
testcase_26 AC 9 ms
6,548 KB
testcase_27 AC 11 ms
6,548 KB
testcase_28 AC 4 ms
6,548 KB
testcase_29 AC 11 ms
6,548 KB
testcase_30 AC 52 ms
6,548 KB
testcase_31 AC 4 ms
6,548 KB
testcase_32 AC 4 ms
6,548 KB
testcase_33 AC 2 ms
6,548 KB
testcase_34 AC 1 ms
6,548 KB
testcase_35 AC 2 ms
6,548 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
template<class T> using graph=vector<vector<T>>;
template<class T> using min_priority_queue=priority_queue<T,vector<T>,greater<T>>;
constexpr int INF32=INT_MAX/2;
constexpr ll INF64=1LL<<60;
constexpr array<int,4> DX4={0,1,0,-1};
constexpr array<int,4> DY4={-1,0,1,0};
constexpr array<int,8> DX8={0,1,1,1,0,-1,-1,-1};
constexpr array<int,8> DY8={-1,-1,0,1,1,1,0,-1};
inline int popcnt(ll n){return __builtin_popcountll(n);}
template<class T> inline bool chmax(T& a,const T& b){return a<b?a=b,true:false;}
template<class T> inline bool chmin(T& a,const T& b){return b<a?a=b,true:false;}
#define rep(i,s,n) for(ll i=(ll)(s);i<(ll)(n);i++)
#define rrep(i,s,n) for(ll i=(ll)(s);i>=(ll)(n);i--)
void _main();
int main(){
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout<<fixed<<setprecision(16);
	_main();
}

void _main(){
	int N, M; cin >> N >> M;
	vector<ll> A(N); rep(i,0,N) cin >> A[i];
	vector<tuple<int,int,ll>> edge;
	graph<int> rev(N);
	rep(i,0,M){
		int a, b; cin >> a >> b; a--; b--;
		ll c; cin >> c;
		edge.emplace_back(a, b, A[b]-c);
		rev[b].emplace_back(a);
	}

	vector<bool> used(N);
	queue<int> que;
	used[N-1] = true;
	que.emplace(N-1);
	while(!que.empty()){
		int v = que.front(); que.pop();
		for(int nv:rev[v]){
			if(used[nv]) continue;
			used[nv] = true;
			que.emplace(nv);
		}
	}

	bool inf = true;
	vector<ll> dist(N, -INF64);
	vector<bool> able(N);
	dist[0] = A[0];
	able[0] = true;
	rep(i,0,N+10){
		bool ok = true;
		for(auto [v, nv, c]:edge) if(able[v] && used[v] && used[nv]){
			able[nv] = true;
			if(chmax(dist[nv], dist[v]+c)) ok = false;
		}
		if(ok){
			inf = false;
			break;
		}
	}

	if(inf) cout << "inf" << endl;
	else cout << dist[N-1] << endl;
}
0