結果
問題 | No.2712 Play more! |
ユーザー |
|
提出日時 | 2024-11-01 20:21:39 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 186 ms / 2,000 ms |
コード長 | 1,443 bytes |
コンパイル時間 | 4,270 ms |
コンパイル使用メモリ | 324,396 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-11-01 20:21:46 |
合計ジャッジ時間 | 6,965 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 33 |
ソースコード
#include <bits/extc++.h>int main() {using namespace std;const auto find_shortest_path_cost{[](const unsigned N, const vector<tuple<unsigned, unsigned, long>> &edges, unsigned start, unsigned goal) -> optional<long> {constexpr auto inf{numeric_limits<long>::max() / 2};vector<long> distance(N, inf);distance[start] = 0;for (unsigned j{}; j < 2 * N; j++)for (const auto &[from, to, cost] : edges)if (distance[from] != inf && distance[to] > distance[from] + cost)distance[to] = distance[from] + cost;for (unsigned i{}; i < 2 * N; i++)for (const auto &[from, to, cost] : edges)if (distance[from] != inf && distance[to] > distance[from] + cost)distance[to] = -inf;if (distance[goal] == -inf)return nullopt;return distance[goal];}};unsigned N, M;cin >> N >> M;vector<long> A(N);for (auto &a : A)cin >> a;vector<tuple<unsigned, unsigned, long>> edges(M);for (auto &[a, b, c] : edges) {cin >> a >> b >> c;--a;--b;c = c - A[a];}if (const auto ans{find_shortest_path_cost(N, edges, 0, N - 1)}; ans)cout << A.back() - *ans << endl;elsecout << "inf" << endl;return 0;}