#include using namespace std; #define all(v) (v).begin(),(v).end() #define pb(a) push_back(a) #define rep(i, n) for(int i=0;i std::vector bellman_ford(T &G, int start, int lim = -1){ // T -> vector>> // edge pair -> pair int n = G.size(); std::vector dis(n, INF); dis[start] = 0; if(lim == -1) lim = n * 3; for(int i = 0; i < lim; i ++) {// 2N 回やると検出とか楽 bool update = 0; for(int j = 0; j < n; j ++) { for(auto [cost, to] : G[j]) { if(dis[j] + cost < dis[to]) { dis[to] = dis[j] + cost; // cout << to << " " << dis[to] << endl; if(i >= n - 1 and to == n - 1) { if(dis[to] < INF/2) { flag = 1; break; } } update = 1; } } } if(!update) break; } return dis; } int main() { cin.tie(0); ios::sync_with_stdio(false); ll n, m; cin >> n >> m; vector a(n); rep(i, n) cin >> a[i]; vector>> v(n * 2); rep(i, m) { ll x, y, c; cin >> x >> y >> c; x --; y --; v[x * 2 + 1].push_back({c, y * 2}); } // cout << "jaja" << endl; rep(i, n) v[i*2].push_back({- a[i], i*2+1}); // rep(i, n * 2) { // foa(e, v[i]) cout << i << " " << e.second << " " << e.first << endl; // } auto ret = bellman_ford(v, 0); if(flag) { cout << "inf" << endl; return 0; } // cout << INF << endl; cout << - ret.back() << endl; return 0; }