import std, core.bitop; bool chmin(T)(ref T SE, T MI) { if (SE > MI) { SE = MI; return true; } else { return false; } } bool chmax(T)(ref T SE, T MI) { if (SE < MI) { SE = MI; return true; } else { return false; } } int lowerBound(T)(T[] SE, T MI) { int lo = -1, hi = cast(int)(SE.length); while (hi - lo > 1) { int mid = lo + hi >> 1; (SE[mid] < MI ? lo : hi) = mid; } return hi; } int upperBound(T)(T[] SE, T MI) { int lo = -1, hi = cast(int)(SE.length); while (hi - lo > 1) { int mid = lo + hi >> 1; (SE[mid] > MI ? hi : lo) = mid; } return hi; } void main() { int N, M; readf("%s %s\n", N, M); auto A = readln.chomp.split.to!(int[]); auto a = new int[M]; auto b = new int[M]; auto c = new int[M]; auto G = new int[][](N, 0); auto rG = new int[][](N, 0); foreach (i; 0 .. M) { readf("%s %s %s\n", a[i], b[i], c[i]); --a[i]; --b[i]; G[a[i]] ~= i; rG[b[i]] ~= a[i]; } auto vis = new bool[N]; vis[N - 1] = true; int[] que; que ~= N - 1; while (!que.empty) { int u = que.front; que.popFront; foreach (v; rG[u]) { if (!vis[v]) { vis[v] = true; que ~= v; } } } auto dist = new long[N]; dist[] = long.min; dist[0] = A[0]; foreach (i; 0 .. N * 3) { bool se = false; foreach (u; 0 .. N) { if (!vis[u] || dist[u] == long.min) { continue; } foreach (j; G[u]) { int v = b[j]; if (vis[v] && chmax(dist[v], dist[u] + A[v] - c[j])) { se = true; } } } if (i > N && se) { "inf".writeln; return; } } dist[N - 1].writeln; }