#pragma GCC optimize("Ofast") #include using namespace std; typedef long long int ll; typedef unsigned long long int ull; mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); ll myRand(ll B) { return (ull)rng() % B; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n,m; cin >> n >> m; vector a(n); for (int i = 0; i < n; ++i) { cin >> a[i]; } vector>> g(n); vector> rg(n); for (int i = 0; i < m; ++i) { int x,y,z; cin >> x >> y >> z; x -= 1, y -= 1; g[x].push_back({y, z}); rg[y].push_back(x); } vector ok(n); queue q; q.push(n-1); ok[n-1] = true; while (q.size()) { int s = q.front(); q.pop(); for (int t : rg[s]) { if (!ok[t]) { ok[t] = true; q.push(t); } } } vector dp(n, -1e18); dp[0] = a[0]; priority_queue> pq; pq.push({dp[0], 0}); vector cnt(n); while (pq.size()) { auto p = pq.top(); pq.pop(); ll score = p.first, j = p.second; if (dp[j] != score) continue; cnt[j] += 1; if (cnt[j] >= 10*n) { cout << "inf" << endl; return 0; } for (auto to : g[j]) { ll nxt = score - to.second + a[to.first]; int t = to.first; if (!ok[t]) continue; if (dp[t] < nxt) { dp[t] = nxt; pq.push({nxt, t}); } } } cout << dp.back() << endl; }