結果
| 問題 |
No.2712 Play more!
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-03-27 01:05:43 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 132 ms / 2,000 ms |
| コード長 | 1,169 bytes |
| コンパイル時間 | 3,608 ms |
| コンパイル使用メモリ | 280,648 KB |
| 実行使用メモリ | 7,324 KB |
| 最終ジャッジ日時 | 2025-03-27 01:05:51 |
| 合計ジャッジ時間 | 6,474 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 33 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, s, e) for (int i = (int)(s); i < (int)(e); ++i)
#define all(a) (a).begin(),(a).end()
const ll INF = 1ll << 60;
int main() {
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
int N, M;
cin >> N >> M;
vector<ll> A(N);
rep(i, 0, N) cin >> A[i];
vector<vector<pair<int, ll>>> G(N);
rep(i, 0, M) {
int a, b;
ll c;
cin >> a >> b >> c;
--a, --b;
G[a].push_back({b, c - A[b]});
}
vector<ll> dist(N, INF);
dist[0] = -A[0];
rep(t, 0, N - 1) {
rep(v, 0, N) {
if (dist[v] == INF) continue;
for (auto e : G[v]) {
dist[e.first] = min(dist[e.first], dist[v] + e.second);
}
}
}
ll ans = -dist[N - 1];
rep(t, 0, N) {
rep(v, 0, N) {
if (dist[v] == INF) continue;
for (auto e : G[v]) {
if (dist[e.first] > dist[v] + e.second) dist[e.first] = -INF;
}
}
}
if (dist[N - 1] == -INF) cout << "inf\n";
else cout << ans << '\n';
}