/* -*- coding: utf-8 -*- * * 2712.cc: No.2712 Play more! - yukicoder */ #include #include #include #include #include using namespace std; /* constant */ const int MAX_N = 2500; const long long LINF = 1LL << 62; /* typedef */ typedef long long ll; typedef pair pii; typedef pair pli; typedef vector vpii; /* global variables */ int as[MAX_N], es[MAX_N]; vpii nbrs[MAX_N]; ll ds[MAX_N]; bool fs[MAX_N]; /* subroutines */ bool dijkstra(int n, int st, bool lpf = false) { fill(es, es + n, 0); fill(ds, ds + n, LINF); ds[st] = 0; priority_queue q; q.push({0, st}); while (! q.empty()) { auto [ud, u] = q.top(); q.pop(); ud = -ud; if (ds[u] != ud || es[u] >= n) continue; if (lpf && u == st && ds[u] < 0) return true; for (auto [v, c]: nbrs[u]) { ll vd = ud + c - as[u]; int ve = es[u] + 1; if (ds[v] > vd || (ds[v] == vd && es[v] > ve)) { ds[v] = vd, es[v] = ve; q.push({-vd, v}); } } } return false; } /* main */ int main() { int n, m; scanf("%d%d", &n, &m); for (int i = 0; i < n; i++) scanf("%d", as + i); for (int i = 0; i < m; i++) { int a, b, c; scanf("%d%d%d", &a, &b, &c); a--, b--; nbrs[a].push_back({b, c}); } dijkstra(n, 0); for (int u = 0; u < n; u++) fs[u] = (ds[u] < LINF); for (int u = 0; u < n; u++) if (fs[u] && dijkstra(n, u, true)) { puts("inf"); return 0; } dijkstra(n, 0); printf("%lld\n", -ds[n - 1] + as[n - 1]); return 0; }