#include #ifdef LOCAL #include "./debug.cpp" #else #define debug(...) #define print_line #endif using namespace std; using ll = long long; int main() { int N, M; cin >> N >> M; vector A(N); for (int i = 0; i < N; i++) { cin >> A[i]; } vector>> G(N); vector> rG(N); for (int i = 0; i < M; i++) { int a, b; ll c; cin >> a >> b >> c; a--; b--; G[a].push_back({b, c}); rG[b].push_back(a); } vector reach(N, false); reach[N - 1] = true; queue Q; Q.push(N - 1); while (!Q.empty()) { int now = Q.front(); Q.pop(); for (auto nxt : rG[now]) { if (reach[nxt]) { continue; } reach[nxt] = true; Q.push(nxt); } } vector dst(N, LLONG_MIN); dst[0] = A[0]; for (int i = 0; i < N; i++) { bool fin = true; for (int j = 0; j < N; j++) { if (!reach[j] || dst[j] == LLONG_MIN) { continue; } for (auto [nxt, cost] : G[j]) { if (dst[nxt] < dst[j] - cost + A[nxt]) { dst[nxt] = dst[j] - cost + A[nxt]; fin = false; } } } if (fin) { break; } if (i == N - 1) { cout << "inf" << endl; return 0; } } cout << dst[N - 1] << endl; }