結果
| 問題 |
No.2712 Play more!
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-03-31 14:58:44 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 111 ms / 2,000 ms |
| コード長 | 2,449 bytes |
| コンパイル時間 | 1,580 ms |
| コンパイル使用メモリ | 179,664 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-09-30 23:48:44 |
| 合計ジャッジ時間 | 3,072 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 33 |
ソースコード
#include "bits/stdc++.h"
/*
#include "boost/multiprecision/cpp_int.hpp"
namespace mp = boost::multiprecision;
using i128=mp::cpp_int;
*/
using namespace std;
typedef long long ll;
typedef int64_t i64;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<double> vd;
typedef vector<vd> vvd;
#define rep(i,a,n) for(int i=a;i<n;i++)
#define drep(i,a,n) for(int i=a;i>n;i--)
#define yes(ans) if(ans)cout<<"yes"<<endl;else cout<<"no"<<endl;
#define Yes(ans) if(ans)cout<<"Yes"<<endl;else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl;else cout<<"NO"<<endl;
#define iINF 1000000007
#define lINF 10000000000007
#define llINF 4000000000000000007
#define all(x) x.begin(),x.end()
#define so(x) sort(all(x))
#define re(x) reverse(all(x))
const double PI = acos(-1);
//BFS/DFS
// 返り値なし(副作用 dist変化) miti/有向辺 a/頂点数 b/スタート地点 dist/bからの距離
void BFS(vvll &miti,ll s,vll &dist){ //mitiはmapでもおk
dist[s]=1;
queue<int> que;
que.push(s);
while(1){
if(que.empty()) break;
int r=que.front();
que.pop();
for(int i:miti[r]){
if(dist[i]==0){
que.push(i);
dist[i]=1;
}
}
}
}
//ベルマンフォード
struct edges{
ll from;
ll to;
ll cost;
};
using ve=vector<edges>;
bool bellman(ve &miti,ll s,vll &dist,ll m,vll &cango){ //返り値 なし(副作用 distが変わる)
dist[s]=0;
ll y=1;
ll cnt=0;
while(y){
if(cnt>m){
return 1;
}
y=0;
for(auto i:miti){
if(dist[i.from]+i.cost<dist[i.to]){
dist[i.to]=dist[i.from]+i.cost;
y=1;
}
}
cnt++;
}
return 0;
}
int main(){
ll n,m; cin>>n>>m;
vll d(n); rep(i,0,n) cin>>d[i];
vvll doro(n,vll(0));
ve miti(m);
ll a,b,c;
rep(i,0,m){
cin>>a>>b>>c; a--; b--;
doro[b].push_back(a);
miti[i]={a,b,c-d[a]};
}
vll cango(n);
BFS(doro,n-1,cango);
ve new_miti(0);
rep(i,0,m){
if(cango[miti[i].from]==1&&cango[miti[i].to]==1) new_miti.push_back({miti[i]});
}
vll dist(n,llINF);
bool y=bellman(new_miti,0,dist,m,cango);
if(y) cout<<"inf"<<endl;
else cout<<d[n-1]-dist[n-1]<<endl;
}