#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); for (int i = 0; i < M; i++) { int a, b; ll c; cin >> a >> b >> c; a--; b--; G[a].push_back({b, c}); } 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 (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; }