#include #include using namespace std; using namespace atcoder; using ll = long long; using mint = modint998244353; ll solveF(ll H, ll W, ll K) { vector> dp(W + 1, vector(1 << H, 0)); dp[0][(1 << H) - 1] = 1LL; for (ll j = 0; j < W; j++) { for (ll s = 0; s < (1 << H); s++) { for (ll t = 0; t < (1 << H); t++) { ll u = s & t; ll cnt = __builtin_popcount(u); if (cnt >= K) { dp[j + 1][t] += dp[j][s]; } } } } mint ans = 0; for (ll s = 0; s < (1 << H); s++) { ans += dp[W][s]; } return ans.val(); } ll solveFNaive(ll H, ll W, ll K) { return 0; } typedef ll Weight; struct Edge{ int from, to; Weight weight; int rev; // 無向グラフの対の辺 Edge(int from, int to, Weight weight) : from(from), to(to), weight(weight) { } Edge(int from, int to, Weight weight, int rev) : from(from), to(to), weight(weight), rev(rev){ } }; bool operator < (const Edge &a, const Edge &b){ if(a.weight != b.weight) return a.weight > b.weight; if(a.from != b.from) return a.from > b.from; return a.to > b.to; } typedef vector Edges; typedef vector Graph; typedef vector Array; typedef vector Matrix; void addFlowEdge(Graph &g, int a, int b, Weight c){ g[a].push_back(Edge(a, b, c, g[b].size())); g[b].push_back(Edge(b, a, 0, g[a].size() - 1)); } void addUndirectedEdge(Graph &g, int a, int b, Weight c){ g[a].push_back(Edge(a, b, c, g[b].size())); g[b].push_back(Edge(b, a, c, g[a].size() - 1)); } const Weight INF = 1e17; bool bellmanFord(const Graph &g, int s, vector &dist, vector &prev){ int n = g.size(); bool nagativeRoop = false; dist.assign(n, INF); dist[s] = 0; prev.assign(n, -1); for(int k = 0; k < 4 * n; ++k){ for(int v = 0; v < n; ++v){ for(Edges::const_iterator i=g[v].begin(); i != g[v].end(); ++i){ if(dist[i -> from] != INF && dist[i -> to] > dist[i -> from] + i -> weight){ dist[i -> to] = dist[i -> from] + i-> weight; prev[i -> to] = i -> from; if(k == 4 * n - 1 && i -> to == n - 1){ dist[i -> to] = -INF; nagativeRoop = true; } } } } } return nagativeRoop; } int main() { 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[a].push_back(Edge(a, b, c - A[b])); } vector dist; vector prev; bool negativeRoop = bellmanFord(g, 0, dist, prev); if (negativeRoop) { cout << "inf" << endl; } else { cout << A[0] - dist[N - 1] << endl; } return 0; }