結果
| 問題 |
No.2712 Play more!
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-03-31 18:16:24 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,559 bytes |
| コンパイル時間 | 2,301 ms |
| コンパイル使用メモリ | 200,408 KB |
| 最終ジャッジ日時 | 2025-02-20 18:11:39 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 31 WA * 2 |
ソースコード
#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;
}
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]));
}
if (bell(dist)) {
cout << "inf" << endl;
return;
}
cout << A[0] - dist[n - 1] << endl;
}