#include #include using namespace std; using namespace atcoder; using ll = long long; template struct Edge { ll from, to; T weight; Edge() : from(-1), to(-1) {} Edge(ll from, ll to, T weight) : from(from), to(to), weight(weight) {} }; template struct Graph { ll n; vector>> edges; Graph(ll n) : n(n), edges(n) {} void add(ll from, ll to, T weight) { edges[from].emplace_back(from, to, weight); } }; template struct BellmanFord { Graph g; vector dist; vector prev; bool hasNegativeLoop; BellmanFord(Graph g) : g(g), dist(g.n, inf()), prev(g.n, -1), hasNegativeLoop(false) {} bool run(int s) { const T INF = inf(); const auto eq = [](T a, T b) { return !lt(a, b) && !lt(b, a); }; int n = g.n; dist[s] = zero(); for (int k = 0; k < 2 * n; ++k) { for (int v = 0; v < n; ++v) { for (auto &e: g.edges[v]) { if (!eq(dist[e.from], INF) && lt(dist[e.from] + e.weight, dist[e.to])) { dist[e.to] = dist[e.from] + e.weight; prev[e.to] = e.from; if (k >= n - 1) { dist[e.to] = -INF; hasNegativeLoop = true; } } } } } return hasNegativeLoop; } }; auto add = [](ll a, ll b) { return a + b; }; auto lt = [](ll a, ll b) { return a < b; }; auto zero = []() { return (ll) 0; }; auto inf = []() { return (ll) 1e17; }; void solveE() { ll N, M; cin >> N >> M; vector A(N); for (ll i = 0; i < N; i++) { cin >> A[i]; } Graph g(N); for (ll i = 0; i < M; i++) { ll a, b, c; cin >> a >> b >> c; a--; b--; g.add(a, b, c - A[b]); } BellmanFord bellmanFord(g); bellmanFord.run(0); if (bellmanFord.dist[N - 1] == -inf()) { cout << "inf" << endl; } else { cout << A[0] - bellmanFord.dist[N - 1] << endl; } } int main() { ios::sync_with_stdio(false); solveE(); return 0; }