結果

問題 No.2712 Play more!
ユーザー startcppstartcpp
提出日時 2024-03-31 16:27:54
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 128 ms / 2,000 ms
コード長 1,983 bytes
コンパイル時間 915 ms
コンパイル使用メモリ 92,028 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-04-03 12:11:11
合計ジャッジ時間 2,954 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 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 50 ms
6,676 KB
testcase_08 AC 52 ms
6,676 KB
testcase_09 AC 50 ms
6,676 KB
testcase_10 AC 2 ms
6,676 KB
testcase_11 AC 22 ms
6,676 KB
testcase_12 AC 91 ms
6,676 KB
testcase_13 AC 14 ms
6,676 KB
testcase_14 AC 55 ms
6,676 KB
testcase_15 AC 128 ms
6,676 KB
testcase_16 AC 10 ms
6,676 KB
testcase_17 AC 5 ms
6,676 KB
testcase_18 AC 12 ms
6,676 KB
testcase_19 AC 5 ms
6,676 KB
testcase_20 AC 22 ms
6,676 KB
testcase_21 AC 13 ms
6,676 KB
testcase_22 AC 82 ms
6,676 KB
testcase_23 AC 7 ms
6,676 KB
testcase_24 AC 12 ms
6,676 KB
testcase_25 AC 5 ms
6,676 KB
testcase_26 AC 16 ms
6,676 KB
testcase_27 AC 35 ms
6,676 KB
testcase_28 AC 67 ms
6,676 KB
testcase_29 AC 15 ms
6,676 KB
testcase_30 AC 94 ms
6,676 KB
testcase_31 AC 98 ms
6,676 KB
testcase_32 AC 87 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 #

//ゴールに到達可能な頂点集合について時刻N以降の更新が起きる場合はinf
//↑をしないで頂点N-1を監視するだけでは「ループの関係しない所からクソデカスコアにできる」場合にループ検出できないので注意
//-INF → -INF + α と遷移する場合を更新とみなすのもよくないので、-INFからは遷移できないようにする
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <cstdio>
#include <cmath>
#include <cassert>
#define rep(i, n) for(i = 0; i < n; i++)
#define int long long
using namespace std;

const int INF = 1e+16;
int n, m;
int a[2500];
vector<int> et[2500], rev_et[2500];
vector<int> ec[2500];
bool can_goal[2500];
int dp[2500], ndp[2500], high[2500];

signed main() {
	int i, j, k;

	cin >> n >> m;
	rep(i, n) cin >> a[i];
	rep(i, m) {
		int u, v, c;
		cin >> u >> v >> c;
		u--; v--;
		et[u].push_back(v);
		ec[u].push_back(c);
		rev_et[v].push_back(u);
	}

	queue<int> que;
	que.push(n - 1);
	can_goal[n - 1] = true;
	while (!que.empty()) {
		int v = que.front(); que.pop();
		for (int nv: rev_et[v]) {
			if (can_goal[nv] == false) {
				can_goal[nv] = true;
				que.push(nv);
			}
		}
	}

	rep(i, n) dp[i] = -INF;
	rep(i, n) ndp[i] = -INF;
	rep(i, n) high[i] = -INF;

	dp[0] = a[0];

	int ans = -INF;
	rep(i, 2 * n) {
		rep(j, n) {
			//if (dp[j] == -INF) continue; //始点から到達できない頂点を遷移元にしない
			rep(k, et[j].size()) {
				int u = j;
				int v = et[j][k];
				int val = dp[u] - ec[j][k] + a[v];
				ndp[v] = max(ndp[v], val);
				if (can_goal[v] && high[v] < ndp[v] && i >= n) {
					cout << "inf" << endl;
					return 0;
				}
				high[v] = max(high[v], ndp[v]);
			}
		}
		ans = max(ans, ndp[n - 1]);
		rep(j, n) dp[j] = ndp[j];
		rep(j, n) ndp[j] = -INF;
	}

	cout << ans << endl;
	return 0;
}
0