#include using namespace std; template using min_priority_queue = priority_queue,greater>; template void printv(vector &v){ bool b = false; for(auto i : v){ if(b) cout << " "; else b = true; cout << i; } cout << endl; } template bool chmin(T &a, const T& b) { if (a > b) { a = b; // aをbで更新 return true; } return false; } template bool chmax(T &a, const T& b) { if (a < b) { a = b; // aをbで更新 return true; } return false; } void yn(bool b){ if(b) cout << "Yes" << endl; else cout << "No" << endl; } bool debug; bool randomInput; bool debugOutput; int numOfTestCase; using ans_type = int; void input(){ if(numOfTestCase > 1){ ; } if(randomInput){ } else{ } return; } void output_input(){ ; } ans_type calc(){ int N, M; cin >> N >> M; vector A(N); for(auto &a : A) cin >> a; vector> V(M); for(auto &[a, b, c] : V){ cin >> a >> b >> c; a--; b--; } vector>> G(2*N); vector>> Ginv(2*N); for(auto[a, b, c] : V){ G[2*a+1].push_back({c, 2*b}); Ginv[2*b].push_back({c, 2*a+1}); } for(int i = 0; i < N; i++){ G[2*i].push_back({-A[i], 2*i+1}); Ginv[2*i+1].push_back({-A[i], 2*i}); } int64_t INF = 1001002003004005006; vector D(2*N, INF); D[0] = 0; for(int i = 0; i < 2*N-1; i++){ for(int j = 0; j < 2*N-1; j++){ for(auto[d, k] : G[j]){ chmin(D[k], D[j]+d); } } } vector W; for(int j = 0; j < 2*N-1; j++){ for(auto[d, k] : G[j]){ if(D[k] > D[j]+d){ W.push_back(k); } } } vector check(2*N, false); queue q; check[2*N-1] = true; q.push(2*N-1); while(q.size()){ int pos = q.front(); q.pop(); for(auto [e, j] : Ginv[pos]){ if(check[j]) continue; check[j] = true; q.push(j); } } for(int i : W){ if(check[i]){ cout << "inf" << endl; return 0; } } cout << -D[2*N-1] << endl; //for(auto i : D) cout << i << " ";cout << endl; return ans_type(); } ans_type calc_simple(){ return ans_type(); } void output(ans_type ans){ return; } int main(){ debug = 0; randomInput = 0; debugOutput = 0; numOfTestCase = 1; srand(time(NULL)); cout << fixed << setprecision(12); if(numOfTestCase == 0) cin >> numOfTestCase; if(debug){ for(int i = 0; i < numOfTestCase; i++){ input(); ans_type ans = calc(); ans_type ansSimple = calc_simple(); if(ans != ansSimple){ output_input(); output(ans); output(ansSimple); } } } else{ for(int i = 0; i < numOfTestCase; i++){ input(); output(calc()); } } return 0; }