結果
問題 |
No.2712 Play more!
|
ユーザー |
|
提出日時 | 2024-03-31 14:09:00 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 952 bytes |
コンパイル時間 | 724 ms |
コンパイル使用メモリ | 65,672 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-09-30 19:02:48 |
合計ジャッジ時間 | 2,326 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 29 WA * 4 |
ソースコード
#include<iostream> #include<cassert> using namespace std; int N,M; int A[2525]; int a[5000],b[5000]; long c[5000]; long dist[2][2525]; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cin>>N>>M; int now=0; for(int i=0;i<N;i++) { long v; cin>>v; assert(1<=v&&v<=(long)1e9); A[i]=v; dist[now][i]=-1e18; } for(int i=0;i<M;i++) { long u,v,w; cin>>u>>v>>w; assert(1<=u&&u<=N); assert(1<=v&&v<=N); //assert(1<=w&&w<=N); a[i]=u-1,b[i]=v-1,c[i]=w; } dist[now][0]=A[0]; for(int t=1;t<=3*N;t++) { int nxt=1-now; for(int i=0;i<N;i++)dist[nxt][i]=dist[now][i]; for(int i=0;i<M;i++)if(dist[now][a[i]]>(long)-1e18) { dist[nxt][b[i]]=max(dist[nxt][b[i]],dist[now][a[i]]-c[i]+A[b[i]]); } bool fn=false; for(int i=0;i<N;i++)if(dist[now][i]<dist[nxt][i])fn=true; if(!fn)break; if(t>=2*N&&dist[now][N-1]<dist[nxt][N-1]) { cout<<"inf\n"; return 0; } now=nxt; } cout<<dist[now][N-1]<<endl; }