結果
問題 |
No.2712 Play more!
|
ユーザー |
|
提出日時 | 2024-03-31 14:42:44 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,565 bytes |
コンパイル時間 | 661 ms |
コンパイル使用メモリ | 78,180 KB |
最終ジャッジ日時 | 2025-02-20 17:23:15 |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 31 WA * 2 |
ソースコード
#include <algorithm> //fillを使うため #include <iostream> #include <vector> using ll = long long; using namespace std; const ll INF = 1LL << 61; struct edge { ll from; // 出発点 ll to; // 到達点 ll cost; // 移動コスト }; int main() { ll V; // 頂点の数 ll side; // 辺の数 ll S; // 始点 ll G; // 終点 vector<edge> edges; // 移動の情報を保存する cin >> V; cin >> side; vector<ll> A(V); for (ll& a : A) cin >> a; S = 0; G = V - 1; vector<ll> d(V, INF); // 始点から添え字の頂点に行くのにかかるコスト d[S] = 0; // 始点を0にする for (int i = 0; i < side; i++) { struct edge add; cin >> add.from; add.from--; cin >> add.to; add.to--; cin >> add.cost; add.cost -= A[add.to]; edges.push_back(add); } for (int i = 0; i < V; i++) { for (int j = 0; j < (int)edges.size(); j++) { struct edge e = edges[j]; if (d[e.to] > d[e.from] + e.cost) { // 移動した後のコストが小さいと、頂点のコストを更新 d[e.to] = d[e.from] + e.cost; if (i == V - 1) { // 頂点の数と同じ回数ループすると、負の閉路があるのでループをぬける cout << "inf" << endl; return 0; } } } } cout << A[S] - d[G] << endl; }