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); foreach (i; 0 .. M) { readf("%s %s %s\n", a[i], b[i], c[i]); --a[i]; --b[i]; G[a[i]] ~= i; } auto dist = new long[N]; dist[] = long.min; dist[0] = A[0]; foreach (i; 0 .. N * 3) { bool se = false; foreach (u; 0 .. N) { foreach (j; G[u]) { int v = u ^ a[j] ^ b[j]; if (chmax(dist[v], dist[u] + A[v] - c[j])) { se = true; } } } if (i > N && se) { "inf".writeln; return; } } dist[N - 1].writeln; }