#include using namespace std; #define rep(i,n) for(int i = 0;i < n;i++) template bool chmin(T &a,T b){ if(a>b){a = b;return true;} return false; } template bool chmax(T &a,T b){ if(a using namespace std; using ll = long long; const ll INF = LLONG_MAX/3; struct Edge{ int to; ll w;//cost Edge(int to, ll w):to(to),w(w){}//コンストラクタ 頂点番号、コスト }; using Graph = vector>; vectorcan_go; //負の閉路があるかどうかと、ない場合はvectorを返す pair> BellmanFord(Graph &G, int s){ int N = (int)G.size(); bool exist_negative_cycle = false;//一旦負の閉路がないことに vectordist(N,INF); dist[s]=0; for(int i = 0;i < N;i++){//頂点数だけ緩和をする if(can_go[i]==false)continue; bool update = false;//更新が発生したかどうか for(int v = 0;v < N;v++){ if(can_go[v]==false)continue; if(dist[v]==INF)continue;//まだ見なくていい for(auto e:G[v]){ if(chmin(dist[e.to],dist[v]+e.w)){ update = true; } } } if(!update)break;//既に最短経路長が求まってる if(i==N-1&&update)exist_negative_cycle = true;//負の閉路がある場合 } return pair>(exist_negative_cycle,dist); } int main(){ #define int long long //移動時間-攻略時間を最小に int N,M;cin >> N >> M; can_go.resize(N,false);//iからN-1に到達できないなら、除外 vectorA(N);//攻略時間 rep(i,N)cin >> A[i]; Graph G(N); vector>rg(N); //頂点0の攻略は最後に考慮すればよい rep(i,M){ int a,b,c;cin >> a >> b >> c; //移動と、行先の攻略時間 a--;b--; G[a].emplace_back(b,c-A[a]);//移動-頂点bの攻略 rg[b].push_back(a); } queueque; can_go[N-1] = true; que.push(N-1); while(!que.empty()){ int q = que.front();que.pop(); for(auto p:rg[q]){ if(can_go[p])continue; can_go[p] = true; que.push(p); } } // for(auto p:can_go)cout << p << ' '; // cout << endl; auto [f,d] = BellmanFord(G,0); if(f){ cout << "inf" << endl;return 0; } int res = d[N-1]; cout << (res-A[N-1])*-1LL << endl; }