結果
問題 |
No.2712 Play more!
|
ユーザー |
|
提出日時 | 2024-03-31 18:23:39 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 59 ms / 2,000 ms |
コード長 | 1,832 bytes |
コンパイル時間 | 2,015 ms |
コンパイル使用メモリ | 200,008 KB |
最終ジャッジ日時 | 2025-02-20 18:12:09 |
ジャッジサーバーID (参考情報) |
judge3 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 33 |
ソースコード
#include <bits/stdc++.h> #include <atcoder/modint> using mint = atcoder::modint998244353; using namespace std; using ll = long long; using ld = long double; template <class T = ll> using vc = vector<T>; template <class T = ll> using vvc = vc<vc<T>>; void solve(); int main() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); ll t = 1; // cin >> t; for (int i = 1; i <= t; i++) solve(); return 0; } #define rep(i, a, b) for (ll i = (a); i < (b); i++) ll dy[4] = {0, 1, 0, -1}, dx[4] = {1, 0, -1, 0}; struct Edge { ll from, to, cost; Edge(ll from, ll to, ll cost) : from(from), to(to), cost(cost) {} }; void solve() { ll n, m; cin >> n >> m; vc<ll> A(n); rep(i, 0, n) cin >> A[i]; vc<Edge> edges; const ll INF = 1LL << 60; auto bell = [&](vc<ll>& dist) -> bool { dist[0] = 0; rep(i, 0, n) { bool update = false; for (auto e : edges) { if (dist[e.from] == INF) continue; if (dist[e.to] > dist[e.from] + e.cost) { dist[e.to] = dist[e.from] + e.cost; update = true; } } if (!update) return false; } rep(i, 0, n) { for (auto e : edges) { if (dist[e.from] == INF) continue; if (dist[e.to] > dist[e.from] + e.cost) { dist[e.to] = -INF; } } } return true; }; vc<ll> dist(n, INF); rep(i, 0, m) { ll a, b, c; cin >> a >> b >> c; a--, b--; edges.push_back(Edge(a, b, c - A[b])); } bell(dist); if (dist[n - 1] == -INF) { cout << "inf" << endl; return; } cout << A[0] - dist[n - 1] << endl; }