結果
問題 | No.2712 Play more! |
ユーザー |
|
提出日時 | 2024-05-14 13:47:34 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 195 ms / 2,000 ms |
コード長 | 1,272 bytes |
コンパイル時間 | 4,429 ms |
コンパイル使用メモリ | 258,024 KB |
最終ジャッジ日時 | 2025-02-21 14:00:58 |
ジャッジサーバーID (参考情報) |
judge2 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 33 |
ソースコード
#include<bits/stdc++.h>using namespace std;#include<atcoder/all>using namespace atcoder;using ll = long long;int N,M;vector<ll> A;using P = pair<ll,ll>;vector<vector<P>> G;vector<vector<P>> nG;void solve(){nG = vector<vector<P>>(N);for(int i = 0;i<N;i++){for(auto &[to,cost]:G[i]){nG[i].push_back({to,-A[to]+cost});}}vector<ll> dist(N,1e18);dist[0] = -A[0];for(int t= 0;t<N*2;t++){for(int i = 0;i<N;i++){for(auto [to,cost]:nG[i]){if(dist[to]>dist[i]+cost){dist[to] = dist[i]+cost;}}}}vector<int> updated(N);ll INF = 1e18;for(int t = 0;t<N;t++){for(int i = 0;i<N;i++){for(auto [to,cost]:nG[i]){if(dist[to]>dist[i]+cost){dist[to] = dist[i]+cost;updated[to] = 1;}}}}for(int t = 0;t < N;t++){for(int i = 0;i<N;i++){for(auto [to,cost]:nG[i]){if(updated[i]){updated[to] = 1;}}}}if(updated[N-1]){cout<< "inf" << endl;}else{cout << -dist[N-1] << endl;}}signed main(){cin.tie(nullptr);ios::sync_with_stdio(false);cin >> N >> M;A.resize(N);for(int i = 0; i < N; ++i) cin >> A[i];G.resize(N);for(int i = 0; i < M; ++i){ll a,b,c;cin >> a >> b >> c;--a; --b;G[a].push_back({b,c});}solve();}